Jump to content

Combine validators together with formvalidation.io ?


ScreamerHS

Recommended Posts

I'm using a Bootstrap multiselect (https://github.com/davidstutz/bootstrap-multiselect ) which I want to validate on a form (defaultForm) with a formvalidator (The best jQuery validation plugin to validate form fields, support Bootstrap, Foundation, Pure, SemanticUI, UIKit frameworks - FormValidation) .

This example works fine. It revalidate on selecting a option from the multiselect.

'tags[]': {
                   validators: {
                        callback: {
                            message: 'Select one or more options</font>',
                            callback: function(value, validator, $field) {
                                    var options = validator.getFieldElements('tags[]').val();
                                    return (options != null && options.length >= 1 && options.length <= 10);
                            }
                        }
                    }
                },

But I want this to validate when another dropdown menu has selected "Yes". (it has two options as a answer - Yes and No). I also get this thing to work with the following code.

'tags[]': { 
                   validators: { 
                        callback: { 
                            message: 'Select one or more options</font>', 
                            callback: function(value, validator, $field) { 
                                   var x = document.getElementById("data_important"); 
                                   var i = x.selectedIndex; 
                                   return (x.options[i].text == 'No') ? true : (x.options[i].text == ''); 
                            } 
                        } 
                    } 
                },  

So both options works fine, but I can't get them combine together, that the it's going to validate only when another dropdown (data_important) is chosen"Yes" and that it revalidates when selecting a option on the multiselect with name "tags[]".



Is there a fix to combine them together, that both elements works?

 

 

post-169867-0-81105000-1487082783_thumb.png

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.