Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit 294099b

Browse files
Minor Safari bug
1 parent 85e3e8f commit 294099b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

min/jquery.easy-validation.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.easy-validation.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
**/
2828

29-
(function( $, document, UA ){
29+
(function( $, document, window, UA ){
3030

3131
var FALSE = false,
3232
TRUE = true,
@@ -88,7 +88,8 @@
8888
$error = $('<strong class="error-message"/>'),
8989
empty = $form.data(EMPTY) || DEFAULT_EMPTY_MSG,
9090
invalid = $form.data(INVALID) || DEFAULT_INVALID_MSG,
91-
error = FALSE; // optimism
91+
error = FALSE, // optimism
92+
$first = $([]);
9293

9394
$form
9495
// cleanup
@@ -116,6 +117,10 @@
116117
$container.addClass( ERROR )
117118
);
118119
error = TRUE;
120+
if ( ! $first.length )
121+
{
122+
$first = $field;
123+
}
119124
}
120125
// not required or not empty
121126
else
@@ -133,10 +138,21 @@
133138
$container.addClass( ERROR )
134139
);
135140
error = TRUE;
141+
if ( ! $first.length )
142+
{
143+
$first = $field;
144+
}
136145
}
137146
}
138147
}
139148
});
149+
150+
// scroll to the first error
151+
if ( $first.length )
152+
{
153+
window.scrollTo( $first.offset().top );
154+
}
155+
140156
return ! error;
141157
});
142158

@@ -172,6 +188,8 @@
172188

173189
this.setCustomValidity( msg );
174190

191+
window.scrollTo( $this.offset().top );
192+
175193
})
176194
// reset
177195
.on( 'change', function(){
@@ -191,4 +209,4 @@
191209
}
192210

193211

194-
})( jQuery, document, navigator.userAgent.toLowerCase() );
212+
})( jQuery, document, window, navigator.userAgent.toLowerCase() );

0 commit comments

Comments
 (0)