Chosen: Making a chosen input a required field

Created on 14 Feb 2012  路  6Comments  路  Source: harvesthq/chosen

My original markup sets the select to be a required field, however Chosen doesn't seem to comply to that?

Most helpful comment

If you're using Chosen for all select elements, you can use this CSS to change make it visible (to DOM), but no opacity, no height, absolute position.

These CSS selectors target invalid select elements, with one of them targeting multiple adding a 15px margin-top to center it on the multiselect elements.

select:invalid {
    height: 0px !important;
    opacity: 0 !important;
    position: absolute !important;
    display: flex !important;
}

select:invalid[multiple] {
    margin-top: 15px !important;
}

Demo: http://jsfiddle.net/tripflex/2zdeu9oc/

All 6 comments

@jbrooksuk did you ever find a solution for this? jQuery Validate doesn't seem to allow me to force the field to be required either.

I have a patch to this referenced in #515 and pull request in #900.

I ended up writing a helper function which performs this check manually on chosen elements. I'll dig it out tomorrow if I can find it, although in the mean time @CaptainN's solution looks good :+1:

This is a dupe of https://github.com/harvesthq/chosen/issues/515. We wil be following up there. Thanks.

515 is technically a dupe of this, but yeah okay.

If you're using Chosen for all select elements, you can use this CSS to change make it visible (to DOM), but no opacity, no height, absolute position.

These CSS selectors target invalid select elements, with one of them targeting multiple adding a 15px margin-top to center it on the multiselect elements.

select:invalid {
    height: 0px !important;
    opacity: 0 !important;
    position: absolute !important;
    display: flex !important;
}

select:invalid[multiple] {
    margin-top: 15px !important;
}

Demo: http://jsfiddle.net/tripflex/2zdeu9oc/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lordspace picture lordspace  路  6Comments

Jeckerson picture Jeckerson  路  7Comments

SFPink picture SFPink  路  9Comments

piercemcgeough picture piercemcgeough  路  5Comments

blankhang picture blankhang  路  7Comments