jqueryformvalidation-plugin

Formvalidation validators cross fields


I've spent nearly 3 hours trying to understand why following chunk of code is validating all inputs to be numeric:

<td class="form-group">
  <input class="form-control" type="text" name="units[]" id="units_0" value="1" size="2" data-fv-notempty="true" data-fv-notempty-message="Valor Requerido" data-fv-regexp="true" data-fv-regexp-regexp="^[0-9]+$" data-fv-regexp-message="Introducir Valor Entero" onchange="calcAmount(this)"/>
</td>

<td class="form-group">
  <input class="form-control" type="text" name="concepts[]" id="concepts_0" size="50" data-fv-notempty="true" data-fv-notempty-message="Introducir Concepto" data-fv-regexp="true" data-fv-regex-regexp="^[0-9|a-z|A-Z|-]{4}$" data-fv-regexp-message="Al menos 4 Caracteres Válidos"/>
</td>

<td class="form-group">
  <input class="form-control" type="text" name="amounts[]" id="amounts_0" size="10" data-fv-notempty="true" data-fv-notempty-message="Valor Requerido" data-fv-regexp="true" data-fv-regexp-regexp="^[0-9]+|[0-9]\.[0-9]+$" data-fv-regexp-message="Valor Numérico esperado" onchange="calcAmount(this)"/>
</td>
<td class="form-group">
  <input class="form-control" type="text" name="subtots[]" value="0.00" id="subtots_0" size=10 readonly/>
</td>
<td class="col-xs-1">
  <a class="badge bg-green addButton"><i class="fa fa-plus-circle"></i></a>
</td>

This is, the input named concepts[] does not validate unless typed text starts with a number. However, the right data-fv-regexp-message is firing.


Solution

  • Sorry people. Got it solved. My Fault.

    Short explanation

    Mix of HTML5 and js formvalidation methods for same inputs.

    Detailed explanation

    As I dynamically add rows (with new fields) to a table, and also add such fields to formvalidation as

    var fields = $('#tr_' + i).find(":input:not([readonly])"); $('#myform').formValidation('addField', inputs);

    And the very first row (its inputs) it was already formvalidated by HTML5 data-fv-*attributes. So somehow validation breaks