Ahmad
Ahmad

Reputation: 887

Select2 not working with Parsley.js when data-parsley-errors-messages-disabled attribute is applied

I am using Parsley.js for validating forms. My requirement is that I can't show the error messages. I need to just highlight the border of the input field or select element. When data-parsley-errors-messages-disabled is present on select element parsley it don't show the message but also it don't highlights the border of the select2 container.

Here is my select code

<select name="someName" required="required" data-parsley-errors-messages-disabled="" data-required="true" class="form-control" id="SomeId">
  <option value="">Select</option>
  <option value="18">Person 18Person 18</option>
  <option value="19">Person 19Person 19</option>
  <option value="20">Person 20Person 20</option>
  <option value="81">Person 81Person 81</option>
  <option value="97">Person 97Person 97</option> 
  <option value="3227">Person 3227Person 3227</option>
</select>

Select2 code:

 $(document).find('select').select2({
    placeholder: 'Select'
});

Please help me what to tweak or adjust to get the desired functionality.

Upvotes: 2

Views: 1286

Answers (1)

Marc-Andr&#233; Lafortune
Marc-Andr&#233; Lafortune

Reputation: 79592

Be careful with select2, it's barely maintained.

I created a PR 2 years ago to address a bug.

Be sure to trigger an input event manually:

$("#select_id").change(function() {
  $("#select_id").trigger('input')
})

There may be other issues too.

Upvotes: 1

Related Questions