new BaseField(obj) → {Object}
Base class for all modules, it provides a link between the html element and
the model. It also implements custom events and validators.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object | Options to initialize BaseField.
Properties
|
- Source:
- lib/BaseField.js, line 7
Returns:
Returns an Object with some base methods.
- Type
- Object
Example
new APP.BaseField({
element: htmlelmenent,
events: ["customEventNameSpace", { * name: "otherCustomEventNamespace",
callback: function(event){
// custom "otherCustomEventNamespace" event callback.
}
}],
validators: [{
validator: function(value) {
return value === 'Dummy';
},
message: "Value should be 'Dummy'"
}],
init: function(){
// this only gets fired after initialization has been completed.
console.log("ready");
}
});
Methods
-
<static> this.bind(evnt, func) → {Object}
-
Bind a callback to a custom event namespace, if the namespace doesn't exists it will create one and add to it.
Parameters:
Name Type Description evnt
String Custom event name. func
Function Callback function to be called when event is triggered. - Source:
- lib/BaseField.js, line 120
Returns:
Returns context for chaining.- Type
- Object
-
<static> this.init() → {Bool}
-
Attach HTMLelement reference, and setup events and validators. Will call a callback function when it's done.
- Source:
- lib/BaseField.js, line 54
Returns:
Returns true with no error occur.- Type
- Bool
-
<static> this.save() → {Object}
-
Update the related element with the value stored in this custom element. Triggers 'save' event, and send the saved value as an event data attribute.
- Source:
- lib/BaseField.js, line 176
Returns:
Returns context for chaining.- Type
- Object
-
<static> this.sync() → {Object}
-
Update the custom element with the value stored in element. Triggers 'sync' event, and send the syncd value as an event data attribute.
- Source:
- lib/BaseField.js, line 192
Returns:
returns context for chaining.- Type
- Object
-
<static> this.trigger(evnt, data) → {Object}
-
Triggers an event from a particular event namespace. Will call all functions that are linked with that namespace with an Event Object. It will have a reference to the element, custom element, event namespace, timestamp and data that can be passed on as part of the trigger.
Parameters:
Name Type Description evnt
String event namespace data
Object data to be passed on as part of the event - Source:
- lib/BaseField.js, line 245
Returns:
returns context for chaining.- Type
- Object
-
<static> this.unbind(evnt, func) → {Object}
-
Unbind the referenced function event from a custom event namespace.
Parameters:
Name Type Description evnt
String Custom event name. func
Function Callback function reference. - Source:
- lib/BaseField.js, line 137
Returns:
Returns context for chaining.- Type
- Object
-
<static> this.update(val, force) → {Object}
-
Update value with a valid specified String. Triggers 'update' event, and send the updated value as an event data attribute.
Parameters:
Name Type Description val
String Value to update field. force
Bool If true, value will be updated regardless of validation. - Source:
- lib/BaseField.js, line 158
Returns:
Returns context for chaining.- Type
- Object
-
<static> this.validate(val) → {Object}
-
Run all custom element validators over the String val. Will return an Object with a property success and a property message with an array of error messages.
Parameters:
Name Type Description val
String Value to be validated - Source:
- lib/BaseField.js, line 210
Returns:
Returns success status, and array of error messages.- Type
- Object