menu

SiteGenesis / Server-side JS / Module: models/FormModel

Classes

FormModel

Methods

(inner) FormModel/clear()

Clears the wrapped form instance.

Source:

(inner) FormModel/copyFrom(updateObject, clear) → {module:models/FormModel~FormModel}

Updates the form with the corresponding property values from the given object.

Parameters:
Name Type Description
updateObject Object

The system object to take property values from.

clear Boolean

Optional. If true, clear the form before updating it.

Source:
Returns:

Returns the updated form.

Type
module:models/FormModel~FormModel

(inner) FormModel/copyTo(updateObject) → {Boolean}T

Updates an object with property values from the form.

Parameters:
Name Type Description
updateObject Object

A Salesforce Commerce Cloud system or custom object to update with form data.

Source:
Returns:

true if the passed object is successfully updated using for the passed group properties specified in the form definition bindings. false if an error is thrown

Type
Boolean

(inner) FormModel/get(formReference) → {module:models/FormModel~FormModel}

Gets a new instance for a given form reference or form object.

Parameters:
Name Type Description
formReference dw.web.FormElement | String

Salesforce form id (/forms/$name$.xml) or Salesforce form object.

Source:
Returns:

A new instance of FormModel that wraps the passed form.

Type
module:models/FormModel~FormModel

(inner) FormModel/get(groupName) → {module:models/FormModel~FormModel}

Gets a new instance of FormModel.

Parameters:
Name Type Description
groupName dw.web.Form | dw.web.FormGroup

The form (group) instance to get from session.forms.

Source:
Returns:

A new instance of a FormModel wrapping the passed form.

Type
module:models/FormModel~FormModel

(inner) FormModel/getBinding()

Gets the bound object of a wrapped form element. Objects are bound to form elements in the form definition.

Source:

(inner) FormModel/getValue()

Returns the value of a subelement.

Source:

(inner) FormModel/handleAction(formHandler)

Handles the submitted form action or calls the error handler in case the form is not valid. If the form does not validate, the TriggeredAction is set to null.

Parameters:
Name Type Description
formHandler Object.<(string|module:models/FormModel~ActionCallback)>

Callbacks for each possible form action. returns null if no explicit error handler is defined.

Source:
Example
require('~/models/FormModel').get('login').handleAction({
    "login" : function(formgroup, action){
        // handle login button
    },
    "register" : function(formgroup, action){
        // handle registration button
    }
});

(inner) FormModel/invalidate()

Invalidates the wrapped form instance.

Parameters:
Name Type Description
Optional. String

If not specified, the error text is configured in the form definition. The "value-error" message is used for FormField instances and "form-error" is used for FormGroup instances. If an error string is passed, it is used in the error message.

Source:

(inner) FormModel/setValue()

Sets the value of a subelement.

Source:

(inner) FormModel/value()

Gets a value from a wrapped form element.

Source: