rguliev / conditionize2.js

jQuery plugin for conditioning things
https://rguliev.github.io/conditionize2.js/demo/index.html
MIT License
22 stars 6 forks source link

Problem with select2 events. #11

Closed thursdaydan closed 3 years ago

thursdaydan commented 3 years ago

Hi all,

I've noticed a potential issue with select2 and this library.

According to the select2 documentation, it should always trigger a change event however, this does not seem to be the case.

I've updated my updatedOn option to include a specific event just for the select2 element.

$('[data-condition]').conditionize({
    updateOn:['change', 'change.select2']
});

The conditionize2 library loads and works fine on other standard inputs and elements, such as when I change my select2 elements to vanilla select elements. I've added an example of my HTML below.

<div class="form-group">
    <label for="badgeable_type">Assignee</label>
    <select class="form-control select2" id="badgeable_type" name="badgeable_type">
        <option value="">Please select an option</option>
        <option value="contact">Contact</option>
        <option value="customer">Customer</option>
    </select>
</div>

<div class="form-group" data-condition="#badgeable_type === 'contact'">
    <label for="badgeable_id">Search Contacts</label>
    <select class="form-control select2Ajax" id="badgeable_id" name="badgeable_id"></select>
</div>

<div class="form-group" data-condition="#badgeable_type === 'customer'">
    <label for="badgeable_id">Search Customers</label>
    <select class="form-control select2Ajax" id="badgeable_id" name="badgeable_id"></select>
</div>
rguliev commented 3 years ago

Hi @thursdaydan,

Sorry for the late reply, it was a busy week.

As for your issue, I was not able to reproduce it. Here is an example on codepen. It works fine with just $('[data-condition]').conditionize() Please provide a complete and reproducible "not working" example of code. That would help to solve the problem.

Thanks:)