diff options
author | Struan Donald <struan@exo.org.uk> | 2013-03-01 13:00:36 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2013-03-01 13:00:36 +0000 |
commit | fcc995e2be0fcdbc6e45d985aff8435587c6227f (patch) | |
tree | f39713dc9c39d0f0ad62dc7606bb2f59ae19a624 /www/js | |
parent | cb43a115cce80e2ec6f1f9466523a30a1fc8377f (diff) |
validate the details screen before progressing
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/views/details.js | 38 | ||||
-rw-r--r-- | www/js/views/fms.js | 15 |
2 files changed, 52 insertions, 1 deletions
diff --git a/www/js/views/details.js b/www/js/views/details.js index 2647624..1b2eb6d 100644 --- a/www/js/views/details.js +++ b/www/js/views/details.js @@ -4,7 +4,43 @@ template: 'details', id: 'details-page', prev: 'photo', - next: 'submit' + next: 'submit', + + onClickButtonPrev: function() { + this.model.set('title', $('#form_title').val()); + this.model.set('details', $('#form_detail').val()); + this.model.set('category', $('#form_category').val()); + this.navigate( this.prev ); + }, + + onClickButtonNext: function() { + this.clearValidationErrors(); + var valid = 1; + + if ( !$('#form_title').val() ) { + valid = 0; + this.validationError( 'form_title', FMS.validationStrings.title ); + } + + if ( !$('#form_detail').val() ) { + valid = 0; + this.validationError( 'form_detail', FMS.validationStrings.detail ); + } + + var cat = $('#form_category').val(); + if ( cat == '-- Pick a category --' ) { + valid = 0; + this.validationError( 'form_category', FMS.validationStrings.category ); + } + + if ( valid ) { + this.clearValidationErrors(); + this.model.set('title', $('#form_title').val()); + this.model.set('detail', $('#form_detail').val()); + this.model.set('category', $('#form_category').val()); + this.navigate( this.next ); + } + } }) }); })(FMS, Backbone, _, $); diff --git a/www/js/views/fms.js b/www/js/views/fms.js index 77961d3..379cd6b 100644 --- a/www/js/views/fms.js +++ b/www/js/views/fms.js @@ -49,6 +49,21 @@ alert(msg); }, + validationError: function( id, error ) { + var el_id = '#' + id; + var el = $(el_id); + var err = '<div for="' + id + '" class="form-error">' + error + '</div>'; + if ( $('div[for='+id+']').length === 0 ) { + el.before(err); + el.addClass('form-error'); + } + }, + + clearValidationErrors: function() { + $('div.form-error').remove(); + $('.form-error').removeClass('form-error'); + }, + destroy: function() { console.log('destory for ' + this.id); this._destroy(); this.remove(); }, _destroy: function() {} |