diff options
| author | mo <mo.khan@gmail.com> | 2017-09-09 11:53:56 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2017-09-09 11:53:56 -0600 |
| commit | 322b4859cd004f3a8556408eab6627d925324c95 (patch) | |
| tree | 2204e07fa52f0ff79cfa64980f6cdc9ec1f7e85a /app/assets/javascripts/models | |
| parent | 1b0a8ea5193578d6bf67722f237ab0a877353e28 (diff) | |
add client side validation to password reset form.
Diffstat (limited to 'app/assets/javascripts/models')
| -rw-r--r-- | app/assets/javascripts/models/password_reset.js.coffee | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/assets/javascripts/models/password_reset.js.coffee b/app/assets/javascripts/models/password_reset.js.coffee new file mode 100644 index 00000000..c9da0a3c --- /dev/null +++ b/app/assets/javascripts/models/password_reset.js.coffee @@ -0,0 +1,20 @@ +#= require ./translation + +class csx.Models.PasswordReset extends Backbone.Model + translation: new csx.Translation('user') + defaults: + email: null + + requiredFields: ['email'] + + validate: (attributes, options) -> + errors = {} + + unless new csx.Models.Email(attributes.email).isValid() + errors['email'] = @translation.errorFor('email', 'invalid') + + _.each @requiredFields, (field) => + if _.isEmpty(attributes[field]) + errors[field] = @translation.errorFor(field, 'blank') + + return errors if _.keys(errors).length > 0 |
