I have a Backbone.Forms editor which is a select menu with true
and false
options. When I convert the string value to boolean and return that in the getValue()
method validation fails. I'm guessing because we are returning false. Also the underlying model always sets the attribute as true because of the string value (thus the reason for boolean).
(function() {
'use strict';
Backbone.Form.editors.BooleanSelect = Backbone.Form.editors.Select.extend({
initialize: function(options) {
options.schema.options = [
{ val: 'true', label: 'Yes' },
{ val: 'false', label: 'No' }
];
Backbone.Form.editors.Select.prototype.initialize.call(this, options);
},
getValue: function() {
return this.$el.val() === 'true' ? true : false;
},
setValue: function(value) {
this.$el.val(value);
}
});
})();
You can override the validate() method (defined in Backbone.Form.editors.Base), that should fix it