File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,26 @@ export default Ember.Component.extend({
3838 */
3939 isSubmitting : false ,
4040
41+ /**
42+ * Scroll to the first input field that does not pass the validation
43+ *
44+ * @returns {void }
45+ */
46+ scrollToFirstError : function ( ) {
47+ var form = this . get ( 'element' ) ;
48+
49+ // We get the first element that fails, and scroll to it
50+ for ( var i = 0 ; i !== form . elements . length ; ++ i ) {
51+ if ( ! form . elements [ i ] . validity . valid ) {
52+ Ember . $ ( 'html, body' ) . animate ( {
53+ scrollTop : Ember . $ ( form . elements [ i ] ) . offset ( ) . top - 40
54+ } , 200 ) ;
55+
56+ break ;
57+ }
58+ }
59+ } ,
60+
4161 actions : {
4262 /**
4363 * @param {string } inputName
@@ -58,6 +78,7 @@ export default Ember.Component.extend({
5878 */
5979 submit ( eventName ) {
6080 if ( ! this . get ( 'element' ) . checkValidity ( ) ) {
81+ this . scrollToFirstError ( ) ;
6182 return false ;
6283 }
6384
Original file line number Diff line number Diff line change 11{
22 "name" : " ember-cli-html5-validation" ,
3- "version" : " 0.2.2 " ,
3+ "version" : " 0.2.3 " ,
44 "description" : " The default blueprint for ember-cli addons." ,
55 "directories" : {
66 "doc" : " doc" ,
You can’t perform that action at this time.
0 commit comments