API¶
-
class
Checksley(jq)¶ The main Checksley class.
Arguments: - jq (object) – JQuery or Zepto instance.
-
updateDefaults(options)¶ Update the default checksley configuration with the options object.
Arguments: - options (object) – Options object to overwrite the defaults
-
updateValidators(validators)¶ Updated (or add) checksley validators.
Params object validators: Validators object to overwrite the checksley validators
-
updateMessages(lang, messages)¶ Updated (or add) checksley messages of a language.
Params string lang: Language code (optional) Params object messages: Messages object to overwrite the language messages.
-
injectPlugin()¶ Inject the plugin on the jQuery or Zepto.
-
setLang(lang)¶ Set the current language.
Arguments: - lang (string) – Language code
-
detectLang()¶ Try to detect the language from the html.
-
getMessage(key, lang)¶ Get a message from a language.
Arguments: - key (string) – The message key
- lang (string) – The language code (optional)
-
class
Form(elm, options={})¶ -
initialize()¶ Initialize the form initializing the fields, binding the events and bindind the data fields.
-
initializeFields()¶ Initialize the Field objects for all the fields of the form.
-
setErrors()¶ Add to html the errors of this form as custom error messages.
Arguments: - errors (object) – An object of key/value with field name as key and error message as value.
-
validate()¶ Validate all the fields of the form.
Returns: boolean
-
bindEvents()¶ Connect valiation to the form events.
-
unbindEvents()¶ Disconnect valiation of the form events.
-
removeErrors()¶ Remove error messages.
-
destroy()¶ Destroy the form.
-
reset()¶ Reset the status of the form.
-
-
class
Field(elm, options={})¶ -
bindData() Unset the data checksley-field attribute to the form storing the
Field()object.
-
unbindData() Unset the data checksley-field attribute to the form storing the
Field()object.
-
focus()¶ Set the focus in the field.
-
eventValidate(event)¶ Handle events that trigger the validation.
Arguments: - event (Event) –
-
unbindEvents() Disconnect valiation of the field events.
-
bindEvents() Connect valiation to the field events.
-
errorClassTarget()¶ # TODO: Review this method Return the target of the error class.
-
resetHtml5Constraints()¶ Reload the constraints of the field based on his html5 type attribute.
-
resetConstraints()¶ Reload the constraints of the field based on his data attributes.
-
hasConstraints()¶ Check if the field has any constraint/validation.
Returns: boolean
-
validate(showErrors) Apply general validators and call
applyValidators().Arguments: - showErrors (boolean) – Enable error showing on this validation.
-
applyValidators(showErrors)¶ Apply specific field validators.
Arguments: - showErrors (boolean) – Enable error showing on this validation.
-
handleClasses(valid)¶ Add/remove classes to the field based on valid param.
Arguments: - valid (boolean) – validation status
-
manageError(name, constraint)¶ Obtain and add to the html the error message for a validation and a constraint.
Arguments: - name (string) – Validator name.
- constraint (object) – Constraint object.
-
setErrors(messages) Add to html the errors of this field as custom error messages.
Arguments: - messages (object) – A string or an array of string with the error messages.
-
makeErrorElement(constraintName, message)¶ Build a li element with the message as content, and with the classes checksley-<constraintName> and <constraintName>.
Arguments: - constraintName (string) – The constraint thats generate the error.
- message (string) – The error mesage.
Returns: Element
-
addError(errorElement)¶ Arguments: - errorElement (Element) – The li element with the error to add.
Add the errorElement to the error container of the field.
-
reset() Reset the status of the field.
-
removeErrors() Remove the field errors.
-
getValue()¶ Get the current value of the field.
Returns: string
-
errorContainerId()¶ Get the error container id.
Returns: string
-
errorContainerClass()¶ Get the error container class.
Returns: string
-
getErrorContainer()¶ Return the field error container (create one if not exists).
-
destroy() Destroy the field.
-
-
class
FieldMultiple(elm, options)¶ Subclass of Field.
-
getSibligns()¶ Get the other fields in the multifield group.
-
getValue() Get the value based on the multiple field type (radio or checkbox).
Returns: string
-
unbindEvents() Disconnect valiation of the field events.
-
bindEvents() Connect valiation to the field events.
-
-
class
ComposedField(elm, options)¶ Subclass of Field.
-
getComponents()¶ Get a list of jQuery objects that compound the composed field based on the data-composed attribute value.
Returns: [element]
-
getValue() Get the value based on the composition of the getComposed() returned fields joined with the data-composed-joiner attribute.
Returns: string
-
unbindEvents() Disconnect valiation of the field events.
-
bindEvents() Connect valiation to the field events.
-