chosen icon indicating copy to clipboard operation
chosen copied to clipboard

Issue #2075: Fix client-side validation

Open jhedstrom opened this issue 8 years ago • 13 comments

Summary

Fixes issue #2075 by not setting display: none and instead leaves the element focusable for browsers that implement client-side validation.

Please double-check that:

  • [x] All changes were made in CoffeeScript files, not JavaScript files.
  • [x] You used Grunt to build the JavaScript files and tested them locally.
  • [x] You've updated both the jQuery and Prototype versions.
  • [x] You haven't manually updated the version number in package.json.
  • [x] If necessary, you've updated the documentation.

jhedstrom avatar Apr 14 '16 19:04 jhedstrom

When will this fix be merged please?

PaddyLock avatar Apr 27 '16 12:04 PaddyLock

.hide() in Prototype also sets the display to none, meaning it is also affected

stof avatar Apr 27 '16 14:04 stof

I've updates the Prototype js as well to use the position/opacity fix.

jhedstrom avatar Apr 27 '16 20:04 jhedstrom

Any thoughts on this?

jhedstrom avatar May 25 '16 20:05 jhedstrom

I've solved it myself by instead of .hide just adding a class chosen-master :)

chosen.jquery.js

this.form_field_jq.addClass('chosen-master').after(this.container);

CSS is:

.chosen-master{ position:absolute; z-index:-1; visibility:hidden; }

yairEO avatar Jun 29 '16 10:06 yairEO

@stof anything else to do here?

jhedstrom avatar Aug 17 '16 21:08 jhedstrom

This is still affecting Drupal form submissions for required fields https://www.drupal.org/node/2705891

acbramley avatar Mar 21 '17 21:03 acbramley

Is there anything left in order to make progress on this issue? Bug is quite annoying and PR has been pending feedback since Aug 2016.

gambry avatar Nov 23 '17 18:11 gambry

I would love to see this fixed. It's popped up as an issue on a Drupal site I am building but the patch in https://www.drupal.org/node/2705891 didn't seem to help.

markconroy avatar Nov 30 '17 09:11 markconroy

This looks good. How can we get it merged?

jonathanbull avatar Oct 21 '19 17:10 jonathanbull

I use

.chosen-master {
  display: inline-block !important;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
}

works with BS4

zonky2 avatar Mar 02 '20 09:03 zonky2

I used @yairEO JS to add a class and @zonky2 CSS for the win!

After that, my required select with a multiple attribute began to work with the browser's validator.

Here's what that looked like for Chosen v1.8.7:

  1. Open chosen.js and on line 199 locate this: this.form_field_jq.hide().after(this.container),

  2. Replace that with this: this.form_field_jq.addClass('chosen-master').after(this.container),

  3. Add these CSS attributes to that class:

.chosen-master {
  display: inline-block !important;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
}

damsalem avatar Oct 22 '20 22:10 damsalem

With the above CSS, Firefox still displays the outline of the hidden field. Adding opacity: 0 fixes that.

DieterHolvoet avatar Dec 18 '23 14:12 DieterHolvoet