DEPRECATION WARNING
This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.
Form¶
Below you can find a list of the available functions with a form instance:
Function | Description |
---|---|
getConfiguration() | Returns the complete configuration. |
getElement() | Returns the form DOM element. |
getFieldByName() | Fetches a given field. |
getFields() | Fetches all the fields of this form. |
getName() | Returns the name of the form. |
onSubmit() | Binds a function on the form submission. |
Fetch the configuration¶
Function
getConfiguration()
Return
Array
Description
Fetches the whole form configuration. It is mostly the TypoScript configuration, so you have access to some values which were previously set in TypoScript.
Example:
var formConfiguration = form.getConfiguration();
var message = formConfiguration['settings']['defaultErrorMessage'];
Get the DOM element¶
Function
getElement()
Return
HTMLFormElement
Description
Returns the DOM element of the form. You may then manipulate it.
Example:
var formElement = form.getElement();
formElement.classList.add('some-class');
Get a given field¶
Function
getFieldByName(name)
Return
Fz.FullField
Parameters
name
: name of the field.
Description
Returns a given field, which you can then manipulate.
Example:
var fieldEmail = form.getFieldByName('email');
Get all fields¶
Function
getFields()
Return
Object<Fz.FullField>
Description
Returns all the fields of this form.
Example:
var fields = form.getFields();
for (var fieldName in fields) {
// ...
}
Get the name of the form¶
Function
getName()
Return
String
Description
Returns the name of the form.
Example:
var message = 'The form ' + form.getName() + ' has been submitted.';
Bind a function on the form submission¶
Function
onSubmit(callback)
Return
/
Parameters
callback
: function called when the form is submitted. If it returns false, the form submission is cancelled.
Description
Binds a function on the form submission. Note that the function wont be called if the form submission is blocked (for instance because of an invalid field).
The function can return false
if the submission must be blocked for any reason.
Example:
form.onSubmit(function() {
var foo = bar();
if (true === foo) {
return false;
}
});