validate onSubmit
This commit is contained in:
parent
3d7df77ae2
commit
c69c0f056b
5 changed files with 43 additions and 45 deletions
12
index.php
12
index.php
|
@ -35,6 +35,14 @@
|
|||
font-size: 130%;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.idealforms.adaptive #invalid {
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
|
||||
.idealforms.adaptive .field.buttons label {
|
||||
height: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -129,7 +137,7 @@
|
|||
|
||||
<div class="field buttons">
|
||||
<label class="main"> </label>
|
||||
<button type="button" class="next">« Previous</button>
|
||||
<button type="button" class="prev">« Prev</button>
|
||||
<button type="button" class="next">Next »</button>
|
||||
</div>
|
||||
|
||||
|
@ -171,7 +179,7 @@
|
|||
|
||||
<div class="field buttons">
|
||||
<label class="main"> </label>
|
||||
<button type="button" class="next">« Previous</button>
|
||||
<button type="button" class="prev">« Prev</button>
|
||||
<button type="submit" class="submit">Submit</button>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -55,13 +55,6 @@ module.exports = {
|
|||
$.idealforms._requests[input.name].abort();
|
||||
this._getField(input).removeClass('ajax');
|
||||
}
|
||||
},
|
||||
|
||||
_validateAll: function(input) {
|
||||
if ($(input).data('idealforms-ajax') && this._getField(input).data('idealforms-valid') === true) {
|
||||
$.idealforms._requests[input.name].abort();
|
||||
this._getField(input).removeClass('ajax');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
4
js/out/jquery.idealforms.min.js
vendored
4
js/out/jquery.idealforms.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -13,16 +13,17 @@ module.exports = {
|
|||
this.$fields = $();
|
||||
this.$inputs = $();
|
||||
|
||||
this.$form.submit(function(e) {
|
||||
e.preventDefault();
|
||||
self.focusFirstInvalid();
|
||||
self.opts.onSubmit.call(self, self.getInvalid().length, e);
|
||||
});
|
||||
|
||||
this._inject('_init');
|
||||
|
||||
this.addRules(this.opts.rules || {});
|
||||
|
||||
this.$form.submit(function(e) {
|
||||
e.preventDefault();
|
||||
self._validateAll();
|
||||
self.focusFirstInvalid();
|
||||
self.opts.onSubmit.call(self, self.getInvalid().length, e);
|
||||
});
|
||||
|
||||
if (! this.opts.silentLoad) this.focusFirstInvalid();
|
||||
},
|
||||
|
||||
|
@ -55,14 +56,7 @@ module.exports = {
|
|||
|
||||
$(input)
|
||||
.on('change keyup', function(e) {
|
||||
|
||||
var oldValue = $field.data('idealforms-value');
|
||||
|
||||
if (e.which == 9 || e.which == 16) return;
|
||||
if (! $(this).is(':checkbox, :radio') && oldValue == this.value) return;
|
||||
|
||||
$field.data('idealforms-value', this.value);
|
||||
|
||||
self._validate(this, true, true);
|
||||
})
|
||||
.focus(function() {
|
||||
|
@ -125,9 +119,17 @@ module.exports = {
|
|||
var self = this
|
||||
, $field = this._getField(input)
|
||||
, userRules = this.opts.rules[input.name].split($.idealforms.ruleSeparator)
|
||||
, oldValue = $field.data('idealforms-value')
|
||||
, valid = true
|
||||
, rule;
|
||||
|
||||
// Don't validate input if value hasn't changed
|
||||
if (! $(input).is(':checkbox, :radio') && oldValue == input.value) {
|
||||
return $field.data('idealforms-valid');
|
||||
}
|
||||
|
||||
$field.data('idealforms-value', input.value);
|
||||
|
||||
// Non-required input with empty value must pass validation
|
||||
if (! input.value && ! this._isRequired(input)) {
|
||||
$field.removeData('idealforms-valid');
|
||||
|
|
Loading…
Reference in a new issue