Form-amd
Form-amd library
form.js is a small library to help form manipulations and validation. This library uses amd structure.
It uses html5 form attributes validate specification and works on browsers that does not support html5 validation. Then, we built it from scratch.
Installation
Install with npm: npm install elo7-form-amd
Dependencies
Form-amd depends on an amd implementation. We suggest async-define implementation for dependency lookup. Form-amd also depends on doc-amd.
Methods
submitOnChange
.submitOnChange(selectorOrDocElement[, callback])
Description:
Submit the parent form when event change is triggered.
Parameters:
selectorOrDocElement: doc-amd object or String //A CSS selector. Note that, if it is a class name with dots, the dots must be escaped. E.g.: doc(".my\\.class")
callback: Function() //A function to call before the event is triggered
Sample:
;
submitOnBlur
.submitOnBlur(selector)
Description:
Submit the parent form when event blur is triggered.
Parameters:
selector: String
Sample:
;
focus
.focus(selector)
Description:
Focus on selected element. If the device is mobile, it calls scrollIntoView function.
Parameters:
selector: String
Sample:
;
validate
.validate(selectorOrDocElement[, object])
Description:
Validate the form using almost all the html5 attributes validate spec.
Parameters:
selectorOrDocElement: doc-amd object or String //A CSS selector. Note that, if it is a class name with dots, the dots must be escaped. E.g.: doc(".my\\.class")
object: Object //An object with the properties messages ("required", "min", "maxlength", "pattern" or "email"), success (function callback) or error (function callback)
Sample:
;
Default messages:
required: This field is requiredmin: Please enter a value greater than or equal to {0}maxlength: Please enter a value with max length less than or equal to {0}pattern: Please enter a valid valueemail: Please enter a valid email address
appendMessage
.append(selector, text)
Description:
Append validation messages
Parameters:
selector: String
text: String
Sample:
;
removeValidationErrors
.removeValidationErrors(selector)
Description:
Removes all validation messages from selected form
Parameters:
selector: String
Sample:
;
License
Form-amd is released under the BSD. Have at it.
Copyright ©️ 2019 Elo7# form-amd