ember-form-validations
v0.0.15-beta.6
Published
A simple addon for validating forms in ember.js
Downloads
12
Readme
Lego blocks
We need a form to have the following properties:
clientFormErrors
: errors due to checks made before a form is submittedserverFormErrors
: errors arising from the request that was madeclientFormErrorStatus
: if errors exist withinclientFormErrors
serverFormErrorStatus
: if errors exist withinserverFormErrors
Usage
- Each of
clientFormErrors
andserverFormErrors
represent key-value pairs of errors. They need to be initialized on the form component e.g
export default Component.extend(ValidatableFormMixin, {
clientFormErrors: EmberObject.create({
identification : null,
password : null
}),
serverFormErrors: EmberObject.create({
credentials: null
})
})
- Within Canopy forms, we wanna satisfy the following
- all errors should show up together at the end of the form before the submit
- the erroneous fields need to be highlighted with a red cross
- focusing into an erroneous field should clear the error
- focusing out of a field should do the validation for whether the field deserves an error
- submit button needs to be disabled if any fields are erroneous
- a server error would mean cleaning out existing client errors
- focusing into a field after getting a server error should clear the server error
ValidatableFormMixin
The ValidatableFormMixin
makes life easier when dealing with the requirements listed out above. The following are made available
- fn
currentFormErrorStatus
(args:type
, which can either beserver
orclient
). returnstrue
orfalse
depending on whether relevant errors exist - fn
updateServerError
(args:property
,error
) - since the server errors are passed on from a parent component, this can be used to update theserverFormErrors
with the relevant error, throughdidUpdateAttrs
for example - fn
updateClientError
(args:property
,error
) - hook
afterServerErrorUpdate
- hook
afterClientErrorUpdate
- hook
afterClearingFieldError
- hook
afterSettingFieldError
- action
setFieldError
(args:field
) - action
clearFieldError
(args:field
)