I'm searching for a way to validate fields that I add to a form after the DOM is loaded and $('#formId').bootstrapValidator()
is executed. Is there a way to add a new field and validate it when the form is submited?
Asked
Active
Viewed 4,798 times
5
3 Answers
6
I was also searching same thing and found solution HERE
However in my case i have destroy bootstrap obj and reinitialize.
$('#sign-up_area').bootstrapValidator('destroy');
$('#sign-up_area').data('bootstrapValidator', null);
$('#sign-up_area').bootstrapValidator();

Muhammad Zeshan Ghafoor
- 303
- 5
- 14
-
1This should be the accepted answer, it solves the question. – Matt K Jan 19 '16 at 20:53
2
There's now a much easier way to accomplish this, using the update
method of Bootstrap Validator:
$('#formId').validator('update')
From the docs:
Updates the collection of inputs that will be validated. Call this method if the set of fields which need to be validated has changed.

developius
- 1,193
- 9
- 17
0
Is there a reason you couldn't use hidden fields when the form first loads and then validate them along with the other fields when the form is submitted?

David Taiaroa
- 25,157
- 7
- 62
- 50
-
I haven't way to know how many new fields will add, can be one or can be ten. So there's no way to know – Jairo Jul 25 '14 at 18:49
-
I was picturing that the base form would load, then you would use maybe jQuery to add the hidden fields as required, then validate everything using Bootstrap validator. Rereading your question, maybe this isn't exactly what you are after though? – David Taiaroa Jul 25 '14 at 20:52
-
Yes. I add fields using jQuery, but there are not hidden, simply don't exists before. That's because the user can select add a simple input text or a input text with four textareas. This is because the fields are for make a survey, and the questions can have multi options or just an open question. The user can add as many questions as he want and this questions can be multi option or simple. – Jairo Jul 29 '14 at 15:59
-
1@Jairo , is there anything here that is helpful? http://bootstrapvalidator.com/examples/adding-dynamic-field/ – David Taiaroa Jul 30 '14 at 12:04