4
I need to validate a form using the browser property required
. Only that there is a problem, my Submit button does not stay on the form. It has to stay out, and when I click on it I call the $('form[name="meu_form"]').submit()
and when I do so it does not validate using the browser.
Example:
HTML
<!-- HTML -->
<form name="meu_form">
Teste campo: <input type="text" name="teste" required />
<br />
<button type='submit'>Enviar que valida o required</button>
</form>
<button class='btnSubmit'>Enviar que não funciona a validação do required</button>
Javascript
//Javascript
$(function(){
$('form[name="meu_form"]').submit(function () {
alert('Aqui faço as chamadas ajax...');
});
$('.btnSubmit').click(function (){
$('form[name="meu_form"]').submit();
});
});
The problem occurs in the following scenario:
If I leave the input
empty and I click the button inside the form
, it validates, if I click on the outside it simply passes. There is how to validate this using the same validation of HTML
, or I have to validate at hand, or else I don’t know, use a plugin for example jQuery Validator?
Cool, but it doesn’t have a method that validates the whole form and displays the messages ?
– Hiago Souza
i can make a var error = false; $('form[name="meu_form"] input, form[name="meu_form"] textarea, form[name="meu_form"] select'). each(Function () ? if(!$(this).checkValidity) { error = true; } }); but simply wanted to use the same HTML validation.
– Hiago Souza