Class: BaseField

customformsjs. BaseField

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
Name Type Description
element Object Object that has an attribute 'value'.
validators Array Field Validators.
events Array Custom events.
init Function Callback function to initialize subclass when BaseField is ready.
Source:
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:
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:
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:
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:
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:
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:
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:
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:
Returns:
Returns success status, and array of error messages.
Type
Object