jQuery validate - rule skip_or_fill_minimum does not fire if used more than once

6

I have a form that is composed of four inputs and they are grouped in pairs.

The rule for this form is very simple, if I fill one of the inputs of the pair, I have to fill in the other one too or do not fill in any. To achieve this behavior I used the skip_or_fill_minimun method.

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 in 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, so 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 not 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 did not find anything related to this in the GitHub issue tracker of this plugin.

UPDATE:

Create an entry in the issue tracker of the plugin at: link .

    
asked by anonymous 06.02.2014 / 23:07

1 answer

3

The problem you're experiencing has been resolved a recent commit .

See your updated Fiddle . I removed the external dependencies, copied and pasted the link code into the beginning of JavaScript, then I've pasted the link code - and by I just kept your JavaScript unchanged.

Then I got the latest "skip_or_fill_minimum" code here: link

And finally, I pasted this code replacing the previous version that was in the Fiddle.

With this, the error is gone! From where it is concluded that the bug in fact existed but has already been corrected.

    
07.02.2014 / 01:33