Model for form functionality.
module:models/FormModel
The Form class
Classes
Methods
(inner) FormModel/clear()
Clears the wrapped form instance.
(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. |
Returns:
Returns the updated form.
(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. |
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. |
Returns:
A new instance of FormModel that wraps the passed form.
(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. |
Returns:
A new instance of a FormModel wrapping the passed form.
(inner) FormModel/getBinding()
Gets the bound object of a wrapped form element. Objects are bound to form elements in the form definition.
(inner) FormModel/getValue()
Returns the value of a subelement.
(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. |
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. |
(inner) FormModel/setValue()
Sets the value of a subelement.
(inner) FormModel/value()
Gets a value from a wrapped form element.