{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveRaven/jqBootstrapValidation/issues/175","labels_url":"https://api.github.com/repos/ReactiveRaven/jqBootstrapValidation/issues/175/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveRaven/jqBootstrapValidation/issues/175/comments","events_url":"https://api.github.com/repos/ReactiveRaven/jqBootstrapValidation/issues/175/events","html_url":"https://github.com/ReactiveRaven/jqBootstrapValidation/issues/175","id":54931082,"number":175,"title":"Can I use this pulgin for dynamic forms?","user":{"login":"vaibhav-jain","id":4224414,"avatar_url":"https://avatars.githubusercontent.com/u/4224414?v=3","gravatar_id":"","url":"https://api.github.com/users/vaibhav-jain","html_url":"https://github.com/vaibhav-jain","followers_url":"https://api.github.com/users/vaibhav-jain/followers","following_url":"https://api.github.com/users/vaibhav-jain/following{/other_user}","gists_url":"https://api.github.com/users/vaibhav-jain/gists{/gist_id}","starred_url":"https://api.github.com/users/vaibhav-jain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vaibhav-jain/subscriptions","organizations_url":"https://api.github.com/users/vaibhav-jain/orgs","repos_url":"https://api.github.com/users/vaibhav-jain/repos","events_url":"https://api.github.com/users/vaibhav-jain/events{/privacy}","received_events_url":"https://api.github.com/users/vaibhav-jain/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-20T19:57:24Z","updated_at":"2015-01-23T08:14:29Z","closed_at":null,"body":"I have a form on which I want to perform validation but this form can be changed dynamically.\r\nFor example: Form for creating `Authors` and more then one `Books` can be added dynamically. Now I want to perform validation for this form. Is it possible with this plugin??? And on some fields I have some function call via `onblur`"},"comment":{"url":"https://api.github.com/repos/ReactiveRaven/jqBootstrapValidation/issues/comments/71160289","html_url":"https://github.com/ReactiveRaven/jqBootstrapValidation/issues/175#issuecomment-71160289","issue_url":"https://api.github.com/repos/ReactiveRaven/jqBootstrapValidation/issues/175","id":71160289,"user":{"login":"eridanaeon","id":10665071,"avatar_url":"https://avatars.githubusercontent.com/u/10665071?v=3","gravatar_id":"","url":"https://api.github.com/users/eridanaeon","html_url":"https://github.com/eridanaeon","followers_url":"https://api.github.com/users/eridanaeon/followers","following_url":"https://api.github.com/users/eridanaeon/following{/other_user}","gists_url":"https://api.github.com/users/eridanaeon/gists{/gist_id}","starred_url":"https://api.github.com/users/eridanaeon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eridanaeon/subscriptions","organizations_url":"https://api.github.com/users/eridanaeon/orgs","repos_url":"https://api.github.com/users/eridanaeon/repos","events_url":"https://api.github.com/users/eridanaeon/events{/privacy}","received_events_url":"https://api.github.com/users/eridanaeon/received_events","type":"User","site_admin":false},"created_at":"2015-01-23T08:14:29Z","updated_at":"2015-01-23T08:14:29Z","body":"Yes you can but you need to make some modification on the code, at method.init :\r\n```javascript\r\nmethods: {\r\n\tinit: function (options) {\r\n\t\tvar settings = $.extend(true, {}, defaults);\r\n\t\tsettings.options = $.extend(true, settings.options, options);\r\n\t\tvar $siblingElements = this;\r\n\r\n\t\tvar uniqueForms = $.unique(\r\n\t\t\t$siblingElements.map(function () {\r\n\t\t\t\treturn $(this).parents(\"form\")[0];\r\n\t\t\t}).toArray()\r\n\t\t);\r\n\r\n\t\t//mod by acs\r\n\t\t$(uniqueForms).unbind(\"submit\");\r\n\t\t\r\n\t\t$(uniqueForms).bind(\"submit\", function (e) {\r\n\t\t\tvar $form = $(this);\r\n\t\t\tvar warningsFound = 0;\r\n.\r\n.\r\n.\r\n.\r\n```\r\n\r\nReason for this is to prevent multiple validations, let's say blur event happened thrice, that would mean three validation actions leading to three calls to submitSuccess / submitError blocks. \r\n\r\nSimilar to what you're doing.... or close enough... validation selector is based on what the user chose, here's how it used it:\r\n\r\n```html\r\n<select \r\n\tid=\"tmf-001\" class=\"span4\" ng-model=\"Type\" \r\n        ng-change=\"modalForm.initValidation();\"\r\n\trequired=\"\" data-validation-required-message=\"select from list\"\r\n>\r\n\t<option value=\"\">Please select</option>\r\n\t<option value=\"1\">1</option>\r\n\t<option value=\"2\">2</option>\r\n</select>\r\n```\r\n\r\n```javascript\r\nthis.initValidation = function(){\r\n\tvar selector1 = '#tmf-001, #tmf-002, #tmf-003, #tmf-004';\r\n\tvar selector2 = '#tmf-001, #tmf-002, #tmf-004';\r\n\tvar selector3 = '#tmf-001';\r\n\tvar selector = '';\r\n\t\r\n   \r\n\t//validation done based on action\r\n\tif(this.action === '1'){\r\n        .       some code for selector\r\n        .\r\n        .\r\n        .\r\n\t\r\n\tif(this.validator.jqBootstrapValidation){\r\n\t\tthis.validator.jqBootstrapValidation('destroy'); //remove previous validations\r\n\t\tdelete this.validator.jqBootstrapValidation;\r\n\t}\r\n\t\r\n\tthis.validator = $(selector).not('[type=submit]').jqBootstrapValidation({\r\n\t\tpreventSubmit: true,\r\n\t\tsubmitError: function ($form, event) {\r\n\t\t\tconsole.log('validation fail');\r\n\t\t\t//do whatever\r\n\t\t},\r\n\t\tsubmitSuccess: function ($form, event) {\r\n\t\t\tconsole.log('validation success, action : ', directive.action);\r\n\t\t\t//do whatever\r\n\t\t}\r\n\t});\r\n};\r\n```\r\n\r\nYou might also want to check this issue,https://github.com/ReactiveRaven/jqBootstrapValidation/issues/157, regarding calls to *'destroy'*"}}