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({
38
38
*/
39
39
isSubmitting : false ,
40
40
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
+
41
61
actions : {
42
62
/**
43
63
* @param {string } inputName
@@ -58,6 +78,7 @@ export default Ember.Component.extend({
58
78
*/
59
79
submit ( eventName ) {
60
80
if ( ! this . get ( 'element' ) . checkValidity ( ) ) {
81
+ this . scrollToFirstError ( ) ;
61
82
return false ;
62
83
}
63
84
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " ember-cli-html5-validation" ,
3
- "version" : " 0.2.2 " ,
3
+ "version" : " 0.2.3 " ,
4
4
"description" : " The default blueprint for ember-cli addons." ,
5
5
"directories" : {
6
6
"doc" : " doc" ,
You can’t perform that action at this time.
0 commit comments