I'm performing date validation for two <input type="text">
fields with jQueryFormValidator
:
$.validate({
modules : 'date'
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="http://cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.1.47/jquery.form-validator.min.js"></script>
<form>
<input type="text" class="form-control" name="Tdesl" maxlength="10" data-validation="date" data-validation-format="dd/mm/yyyy" placeholder="dd/mm/aaaa" OnKeyPress="formatar('##/##/####', this)" id="Cdesl22"></label>
<input class="form-control" type="text" data-validation="date" data-validation-format="dd/mm/yyyy" maxlength="10" placeholder="dd/mm/aaaa" OnKeyPress="formatar('##/##/####', this)" name="Tinsem3" id="Cinsem"></label>
</form>
But I can not make sure that, when these fields are validated, a button ( <button="button">
is not a submit
) is enabled.
According to some answers I saw in SOen, jQueryFormValidator
does not have native support for this function, so I'm trying to adapt this script (the link is from FIDDLE, but I found it by SOen):
$('#myform > input').on('input', function () {
var empty = false;
$('form > input, form > select').each(function () {
if ($(this).val() == '') {
empty = true;
}
});
if (empty) {
$('#register').attr('disabled', 'disabled');
} else {
$('#register').removeAttr('disabled');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><formid="myform">Username
<br />
<input type="text" class="class" id="user_input" name="username" />
<br />Password
<br />
<input type="password" id="pass_input" name="password" />
<br />Confirm Password
<br />
<input type="password" id="v_pass_input" name="v_password" />
<br />Email
<br />
<input type="text" id="email" name="email" />
<br />Birthday
<br />
<input type="date" id="bday" name="birthday" />
<br />Sex
<br />
<select name="sex" id="sex">
<option>Male</option>
<option>female</option>
</select>
<input type="submit" id="register" value="Register" disabled="disabled" />
</form>
However, this script requires that all input
fields be filled in, and I need only two fields (there are more fields in the form, and only two of them must be observed). I tried to create a class to apply in these two fields, but I think I did not do it right:
$('#myform > .classinput').on('input', function () {
In addition, this script uses type date
, while in my case I am using fields of type text
, but are being validated for date, so if it was possible to use the result of the validation (to enable the button ) would be ideal, but otherwise der can be only with the basic rules, type accept for the day maximum 31, month 12, year 2015, etc.