6
I have a form that consists of four inputs
and they are grouped in pairs.
The rule for this form is very simple, if I fill in one of the pair’s inputs, I have to fill in the other as well or fill out none. To achieve this behavior I used the method skip_or_fill_minimun
.
THE HTML:
<div id="msgErros"></div>
<form>
<label for="dataInicial">Data Inicial</label>
<input type="text" name="filtro.dataInicial" id="dataInicial" class="datas" />
<label for="dataFinal">Data Final</label>
<input type="text" name="filtro.dataFinal" id="dataFinal" class="datas" />
<br />
<label for="tempoInicial">Tempo Inicial</label>
<input type="text" name="filtro.tempoInicial" id="tempoInicial" class="tempos" />
<label for="tempoFinal">Tempo Final</label>
<input type="text" name="filtro.tempoFinal" id="tempoFinal" class="tempos" />
<br />
<button type="submit">Enviar</button>
</form>
Validation rules, messages and groups:
$("form").validate({
rules : {
"filtro.dataInicial": {
skip_or_fill_minimum: [2, ".datas"]
},
"filtro.dataFinal": {
skip_or_fill_minimum: [2, ".datas"]
},
"filtro.tempoInicial": {
skip_or_fill_minimum: [2, ".tempos"]
},
"filtro.tempoFinal": {
skip_or_fill_minimum: [2, ".tempos"]
}
},
messages: {
"filtro.dataInicial": {
skip_or_fill_minimum: "Por favor, preencha ambos os campos de data ou nenhum deles."
},
"filtro.dataFinal": {
skip_or_fill_minimum: "Por favor, preencha ambos os campos de data ou nenhum deles."
},
"filtro.tempoInicial": {
skip_or_fill_minimum: "Por favor, preencha ambos os campos de tempo ou nenhum deles."
},
"filtro.tempoFinal": {
skip_or_fill_minimum: "Por favor, preencha ambos os campos de tempo ou nenhum deles."
}
},
groups : {
grupoDatasAtendimentoSintetico : "filtro.dataInicial filtro.dataFinal",
grupoTemposAtendimentoSintetico : "filtro.tempoInicial filtro.tempoFinal"
},
errorContainer : "#msgErros ul",
errorLabelContainer : "#msgErros",
wrapper : "li"
});
The problem is that if I fill one of the first two inputs the rule is not triggered, the problem does not occur if I do this with the second pair. If I delete the second pair the rule runs perfectly, then I think it’s a bug. Here’s a fiddle.
I read about this method and require_from_group
causing problems that simply prevent other methods from running, but this bug was supposedly fixed in version 1.11.1 , which is what I’m using in my project and on fiddle both for the plugin itself and its additional methods.
The problem only happens when the user fills in one of the fields in the first pair. Does anyone know if this is another bug? I found nothing related to this in Github Issue tracker of this plugin.
UPDATING:
Create a plugin Issue tracker entry in the address: https://github.com/jzaefferer/jquery-validation/issues/1008.
Are you having this problem in a specific browser? I tried your fiddle on Chrome and Firefox and could not play the problem.
– mgibsonbr
I use the latest Chrome, FF and IE. And how did you test? Fill in the first or second field only and submit the form.
– Philippe Gioseffi
Okay, I get it. The message warning the problem appears, but still he lets you submit the form.
– mgibsonbr
Exactly that, he warns, but submits and should not submit.
– Philippe Gioseffi