Search code examples
twitter-bootstrapformvalidation-plugin

Formvalidation addField doesn't do anything


I'm using formvalidation.io to validate a form in Bootstrap. The form has a dynamic field option, so I am trying to use the addField functionality to make sure that this field is included when the form is validated. As explained here. Unfortunately this doesn't work. The new fields are never included in the validation.

Script to add a new button:

$(document).on("click", '#add-row', function() {
   var rownr = parseInt($(this).attr("data-rownr"));
   rownr = (rownr+1).toString();
   $(this).attr("data-rownr", rownr);
   var rowid = '#contact-rule-'+rownr;
   $(this).before("<input type='text' id='"+rowid+"' name='"+rowid+"'/></div>");
   $option = $(document).find(rowid);
   $('#ruleForm').formValidation('addField', $option);
});

Solution

  • Worked around this by adding all fields in code upfront und making then hidden and using javascript to make them visible again. Also set Formvalidation to exclude hidden fields.