ISSUE:
I developed a custom backbone editor, but when trying to initialize it with Backbone Forms, I encountered an issue where it couldn't find the schema for my editor. Upon investigation, I discovered that Backbone was looking for the schema in the Form.editors
array within the backbone-forms.js
file. How can I properly register the schema for my custom editor?
CONTEXT:
In my implementation of Backbone Forms, the initialization process involves defining fields using the following structure:
backbone-forms.js
var Form = Backbone.View.extend({
// Initialization
initialize: function(options) {
//.....
// Checking and including fields (default is all)
var selectedFields = this.selectedFields = options.fields || _.keys(schema);
_.each(selectedFields, function(key) {
var fieldSchema = schema[key];
fields[key] = this.createField(key, fieldSchema); // <==== This is where issues arise
}, this);
},
//....
}, {
//....
editors: {} // <===== QUESTION: How do I add my custom editor to this array???
});
Challenge: The problem arises when Backbone attempts to create a new Form and calls the createSchema
method which looks like:
createSchema: function(schema) {
//........
// ISSUE: Form.editors[schema.type] is undefined
schema.type = (_.isString(schema.type)) ? Form.editors[schema.type] : schema.type;
return schema;
}
As a result, Form.editors[schema.type] is undefined, preventing me from successfully creating or rendering my custom editor.
Solution: Where and how can I register my custom editor within the Form.editors
array?