Skip to content

Commit edc9710

Browse files
committed
Password confirmation validator: give error message if password field does not exist and fail validation
Previously, this would just throw an exception. Fix form.html validation of PW duplication fields
1 parent a87b9ce commit edc9710

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/modules/security.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
confInputName = $el.valAttr('confirm') || ($el.attr('name') + '_confirmation'),
4343
$confInput = $form.find('[name="' +confInputName+ '"]').eq(0);
4444

45-
if ( $confInput ) {
45+
if ($confInput.length) {
4646
conf = $confInput.val();
4747
if( config.validateOnBlur && !$confInput[0].hasValidationCallback ) {
4848
$confInput[0].hasValidationCallback = true;
@@ -56,7 +56,9 @@
5656
});
5757
}
5858
} else {
59-
alert('Could not find an input with name "'+confInputName+'"');
59+
$.formUtils.warn('Password confirmation validator: could not find an input ' +
60+
'with name "'+confInputName+'"');
61+
return false;
6062
}
6163

6264
return value === conf;

test/form.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,19 @@
233233
</form>
234234
<hr />
235235
<form id="form-b">
236+
<h4>Validate on submit</h4>
236237
<div class="form-group">
237238
<label class="control-label">Test</label>
238239
<input name="test" data-validation="number" type="text" />
239240
</div>
240241
<div class="form-group">
241242
<label class="control-label">Password</label>
242-
<input name="pass" data-validation="confirmation" type="password" />
243+
<input name="pass" type="password" />
243244
</div>
244245
<div class="form-group">
245246
<label class="control-label">Password again</label>
246-
<input name="pass_confirmation" type="password" />
247+
<input data-validation-confirm="pass" type="password"
248+
data-validation="confirmation" />
247249
</div>
248250
<p>
249251
<input type="submit" class="button">

0 commit comments

Comments
 (0)