4
I am performing date validation for two fields <input type="text">
with the jQueryFormValidator
:
$.validate({
modules : 'date'
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="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 cannot make that, when these fields are validated, that a button (<button="button">
is not a submit
) is enabled.
According to some answers I saw in Soen, the jQueryFormValidator
not native support for this function, so I’m trying to adapt that script (the link is 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>
<form id="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 all fields input
are completed, and I need only two (there are more fields on the form, and I need only two of them to be observed). I tried to create a class to apply in these two fields, but I guess I didn’t do it right:
$('#myform > .classinput').on('input', function () {
Also, this script uses the type date
, while in my case I’m using type fields text
, but that are being validated for date, so if it were possible to use the validation result (to enable the button) would be ideal, but otherwise it can only be with the basic rules, like accept for the day at the most 31, in the month 12, in the year 2015, etc.
Cool +1, now only need to validate the field as date before enabling the button.
– gustavox
puts the class='forcing' that solves
– Michel Simões
So, but the field is
text
, and it has to be validated to date before opening the button. In this case it will only require you to have any fill-in, as if it were a text field, and I need it either to take the validation that you use (form-Validator), or to do another one, but any way it validates that it is a correct date before enabling the button...– gustavox