Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class Handler don't remove error class neither message #1122

Closed
rruizf opened this issue Jul 1, 2016 · 5 comments
Closed

Class Handler don't remove error class neither message #1122

rruizf opened this issue Jul 1, 2016 · 5 comments

Comments

@rruizf
Copy link

rruizf commented Jul 1, 2016

Hi, I create a simple form to test. Im using lastest versions of select2 and parsley.js.

HTML:

<form id="frm">
  <div>
  <label for="sel">Label *</label>
  <select id="sel" data-parsley-errors-container="#sel_error" data-parsley-class-handler=".select2-selection" required>
    <option value=""></option>
    <option value="1">Opt 1</option>
    <option value="2">Opt 2</option>
    <option value="3">Opt 3</option>
    <option value="4">Opt 4</option>
  </select>
  </div>
  <div id="sel_error"></div>
  <button type="submit">Send!</button>
</form>

Select2 library, hide the original select and add the next code:

<select id="sel" data-parsley-errors-container="#sel_error" data-parsley-class-handler=".select2-selection" required="" tabindex="-1" class="select2-hidden-accessible" aria-hidden="true" data-parsley-id="5">
    <option value=""></option>
    <option value="1">Opt 1</option>
    <option value="2">Opt 2</option>
    <option value="3">Opt 3</option>
    <option value="4">Opt 4</option>
</select>
<span class="select2 select2-container select2-container--default" dir="ltr" style="width: 56px;">
    <span class="selection">
        <span class="select2-selection select2-selection--single parsley-error" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-sel-container">
            <span class="select2-selection__rendered" id="select2-sel-container">
                <span class="select2-selection__placeholder">Select one</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>

When I try to submit the form without select one item in the select, validation works fine and put class and message error in the right places (.select2-selection for class and #sel_error for message. Last option is because if I don't setup it, message error appears above select, not under #979)
But, if I select an option, class and error message don't dissapear.
I was trying to use the function $('#sel').on('change') of select2 library, to remove them manually, but I don't know how I can check if the form or field were validated at last one time, cause if I select one item and then I unselect it, class and message appears without submit the form.

@marcandre
Copy link
Collaborator

Could you please put together a working example, for example starting from http://codepen.io/marcandre/pen/jqbzyN?editors=101

@rruizf
Copy link
Author

rruizf commented Jul 1, 2016

Hi, sure... here is the complete example:

http://codepen.io/anon/pen/GqmYoz?editors=1000

Cheers.

@rruizf
Copy link
Author

rruizf commented Jul 5, 2016

Any help?

@marcandre
Copy link
Collaborator

Sorry, not much time these days as I'm travelling

@marcandre
Copy link
Collaborator

Thanks for reporting the issue and for creating a working example. Sorry it took me so long to address it.

Looks like select2 triggers 'change' events but not 'input' events.

I've opened a PR to address this, please subscribe to that issue and/or try out that branch.

If you want to address this in the meantime, you would have to detect the change sent by select2 and trigger the input yourself.

Not much else I can do at this point, so I'll close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants