1

I have a form that is validated using validationform.io. There is no out of the box support for Bootstrap select, select fields.

I have this bit of jQuery code that will add the has-success class that adds a green border around the select box and this works fine. But as I'm only finding the .btn-light class it changes anything using that class.

Is there a way to add a CSS selector where class=".btn-light" and data-id="roleId"?

This is my jQuery:

fv.on('core.field.valid', function(field) {   
    if (field === 'roleId') {     
        $('.btn-light').addClass("has-success"); 
    }      
});

This is the html for the select :

<select class="selectpicker show-tick" data-style="btn-light" name="roleId" id="roleId">

this is what the bootstrap-select converts it to when checking in developer tools :

<button type="button" class="btn dropdown-toggle btn-light" data-toggle="dropdown" role="button" data-id="roleId" >

1 Answer 1

3

You can combine the class and data in the selector field:

$('.btn-light[data-id="roleId"]').addClass("has-success"); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.