Functions for registering, looking up, and instantiating editors for
certain Baja types.
Methods
(static) buildFor(params, edopt) → {Promise.<module:bajaux/Widget>}
- Description:
Instantiates an editor as in
makeFor, but with the added steps of
initializing and loading the editor. When the promise resolves, the
editor will be initialized within the DOM, and the passed value will have
been loaded into the editor.
- Source:
Examples
Build a raw editor for a String
fe.buildFor({
value: 'my string',
properties: { multiLine: true },
dom: $('#myStringEditorDiv')
}).then(function (editor) {
//editor is now fully initialized and loaded
});
Build an editor for a slot on a component
var myComponent = baja.$('baja:Component', { mySlot: 'hello world' });
fe.buildFor({
complex: myComponent,
slot: 'mySlot',
properties: { multiLine: true },
dom: ${'#myStringSlotEditorDiv')
}).then(function (editor) {
//editor is now fully initialized and loaded
$('#saveButton').click(function () {
editor.save().then(function () {
alert('your changes are applied to the component');
});
});
});
Build a StringEditor even though you plan to load a different kind of value into it.
fe.buildFor({
type: StringEditor,
value: 5,
dom: $('#myStringEditorDiv')
}).then(function (stringEditor) {
//StringEditor better be able to load the value you specified,
//or this will reject instead.
});
Example showing the effects of the uxFieldEditor facet (BFacets.UX_FIELD_EDITOR). By setting this slot facet to the type spec of a `BIJavaScript` implementation, you can force the usage of a particular field editor instead of relying on the agent registration.
fe.buildFor({
value: 5,
dom: $('#myStringEditorDiv'),
properties: { uxFieldEditor: 'webEditors:StringEditor' }
}).then(function (stringEditor) {
//uxFieldEditor facet enforced usage of StringEditor instead of the
//default NumericEditor
});
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
module:nmodule/webEditors/rc/fe/fe~FeParams |
Properties
|
|||||||||||||
ed |
module:bajaux/Widget |
<optional> |
optionally, |
Returns:
promise to be resolved with the
instance of the editor (fully initialized and loaded), or rejected if
invalid parameters are given (including missing dom parameter).
- Type
- Promise.<module:bajaux/Widget>
(static) getConstructors(type, paramsopt) → {Promise.<Array.<function()>>}
- Description:
Retrieve all available widget constructors for the given type.
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
type |
String | Type | ||||||||||
params |
Object |
<optional> |
Properties
|
Returns:
promise to be resolved with an array
of constructor functions.
- Type
- Promise.<Array.<function()>>
(static) getDefaultConstructor(type, paramsopt) → {Promise.<function()>}
- Description:
Retrieve the
Widgetconstructor function registered for the given Type.
- Source:
Examples
function StringEditor() {} //extends Widget
fe.register('baja:String', StringEditor, {
formFactors: [ Widget.formfactor.mini ]
});
//resolves StringEditor
fe.getDefaultConstructor('baja:String', { formFactors: [ 'mini' ] });
//resolves undefined
fe.getDefaultConstructor('baja:String', { formFactors: [ 'compact' ] });
// Will return myModule's SpecialNumericEditor instead of the default webEditors:NumericEditor
fe.getDefaultConstructor('baja:Double', { properties: { uxFieldEditor: 'myModule:SpecialNumericEditor' } });
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
type |
String | Type | ||||||||||||||
params |
Object |
<optional> |
Properties
|
Returns:
a promise to be resolved with the constructor
function for the given Type, or with undefined if no constructor is
registered. Note that if an invalid RequireJS module ID was passed to
fe.register(), it will still look up the supertype chain in an attempt
to resolve something.
- Type
- Promise.<function()>
(static) makeFor(params) → {Promise.<module:bajaux/Widget>}
- Description:
Instantiate a new editor for a value of a particular Type.
Note that you will receive a constructed instance of the editor, but
it is uninitialized - callinginstantiate()andload()is still your
job. (SeebuildFor.)
- Source:
Example
Instantiate an editor for a baja value. Note that the workflow below is easily simplified by using fe.buildFor() instead.
var myString = 'my string';
fe.makeFor({
value: myString
properties: { multiLine: true }
}).then(function (editor) {
return editor.initialize($('#myStringEditorDiv'))
.then(function () {
return editor.load(myString);
});
});
Parameters:
| Name | Type | Description |
|---|---|---|
params |
module:nmodule/webEditors/rc/fe/fe~FeParams |
Returns:
promise to be resolved with an
editor instance, or rejected if invalid parameters are given.
- Type
- Promise.<module:bajaux/Widget>
(static) register(type, module, paramsopt) → {Promise}
- Description:
Registers a RequireJS module to a baja Type. This takes a RequireJS
module ID string which resolves to a module exporting a constructor for a
Widget subclass.
- Source:
Example
Register StringEditor on baja:String, so that it can be used to build "mini" editors for Strings.
fe.register('baja:String', 'nmodule/webEditors/rc/fe/baja/StringEditor', {
formFactors: [ Widget.formfactor.mini ]
});
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
type |
Type | String | ||||||||||
module |
String | RequireJS module ID |
|||||||||
params |
Object |
<optional> |
Properties
|
Returns:
promise to be resolved after the module
registration is complete. Note that getDefaultConstructor(), makeFor(),
etc. will still work (with some possible extra network calls) before the
promise is fully resolved. Promise will be rejected if RequireJS is unable
to resolve a given module ID.
- Type
- Promise
Type Definitions
FeParams
- Description:
This type describes the available parameters to be passed to the various
methods onfe. These values will be used both to look up the type of the
desired editor, and also to construct that editor. In other words, the
data to look up a widget will also be used in the same turn to construct
that widget. See module:bajaux/Widget
- Source:
This type describes the available parameters to be passed to the various
methods on fe. These values will be used both to look up the type of the
desired editor, and also to construct that editor. In other words, the
data to look up a widget will also be used in the same turn to construct
that widget. See module:bajaux/Widget
Type:
- module:bajaux/lifecycle/WidgetManager~BuildParams | FeSpecificParams