I'm new in both libraries. I began using select2 in some selects and works fine, then I want to validate the form and I use Parsley. Validation is working fine, but I had some problems with CSS class and error message.
Select2 create new tags for the original SELECT, then hide it. I edit the custom.css file of gentelella bootstrap template adding span.parsley-error and in js file of select2, I added an id to one of the new span tags created, so using 'data-parsley-class-handler' and 'data-parsley-errors-container' in the original select I can show the message error in the right position and change CSS to the new SPAN tag created by select2.
The problem is when I select one option from the select items, parsley-error css class is not removed from SPAN, neither the error message.
What I did?:
HTML:
<div class="form-group col-md-2 col-sd-4 col-xs-6">
<label for="casilla_cliente_id" class="control-label">RUT <span class="required">*</span></label>
<select class="select2_single form-control select2-hidden-accessible" tabindex="-1" name="casilla[cliente_id]" data-parsley-errors-container="#er_cliente_id" data-parsley-class-handler="#select2-casilla_cliente_id" required="required" id="casilla_cliente_id" aria-hidden="true">
<option value="" selected="selected"></option>
<option value="14933">1.318.XXX-X | Name 1</option>
<option value="16469">1.363.XXX-X | Name 2</option>
<option value="17268">99.594.XXX-X | Name 3</option>
<option value="16129">99.599.XXX-X | Name 4</option>
</select>
<span class="select2 select2-container select2-container--default select2-container--focus" dir="ltr" style="width: 153px;">
<span class="selection">
<span id="select2-casilla_cliente_id" class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="-1" aria-labelledby="select2-casilla_cliente_id-container">
<span class="select2-selection__rendered" id="select2-casilla_cliente_id-container">
<span class="select2-selection__placeholder">RUT</span>
</span>
<span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span>
</span>
</span>
<span class="dropdown-wrapper" aria-hidden="true"></span>
</span>
<span id="er_cliente_id"></span>
</div>
custom.css file from gentelella bootstrap template:
span.parsley-error, input.parsley-error, textarea.parsley-error, select.parsley-error {
background: #FAEDEC !important;
border: 1px solid #E85445 !important;
}
select2.full.js:
BaseSelection.prototype.render = function () {
var $selection = $(
'<span id="select2-' + this.$element.attr('id') + '" class="select2-selection" role="combobox" ' +
' aria-haspopup="true" aria-expanded="false">' +
'</span>'
);
I hope somebody can help me in remove the CSS class and error message from select2 when I select one option in select.
Thanks in advance.