I need to validate a form using the browser with the required
property. Only that there is a problem, my submit button is not on the form. It has to stay out, and when I click on it I call $('form[name="meu_form"]').submit()
and when I do this 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 click the button inside the form
, it validates, if I click on the outside it just goes by. Is there a way to validate this using the same validation of HTML
, or do I really have to validate at hand, or do not know, use a plugin for example jQuery Validator?