react-select icon indicating copy to clipboard operation
react-select copied to clipboard

HTML 5 required validation not working when searchable is set to false

Open jariwalabhavesh opened this issue 9 years ago • 8 comments

react-select require validation has issue with searchable option:

when searchable set to true. It is working fine. but when searchable set to false it is not validating html 5 require validation.

Here is plunker link where i had regenerate issue https://plnkr.co/edit/y7udXxoN2mFMXF5GOZhY?p=preview

in plunker script.jsx file please test it by changing value of searchable attribute. if you make it true it will show default browser html5 validation popup and if you make it false it will not validate.

Thanks

jariwalabhavesh avatar Jun 26 '17 13:06 jariwalabhavesh

same here, do you have updates about this?

optyler avatar Jul 18 '17 08:07 optyler

@optyler No any update or feedback on this issue :-(

jariwalabhavesh avatar Jul 18 '17 12:07 jariwalabhavesh

I ran into the same issue. I used the work-around from #1397 by @Ryanthegiantlion: wrapping the select component with a sibling input with zero height, width, and opacity and assigned the required prop to that input (as well as autoComplete). It seems like the solution within the library would be a similar hidden input, but this was sufficient for my immediate needs.

<div className={className}>
    <Select {...props}></Select>
    <input
        tabIndex={-1}
        autoComplete={props.autoComplete}
        value={props.value}
        required={props.required}
        onChange={e => props.onChange({value: e.target.value})}
    ></input>
</div>

benkahle avatar Jul 20 '17 17:07 benkahle

I just got the same issue, any progress on this ?

gregaubert avatar Jan 23 '18 15:01 gregaubert

I just got as well the same issue, any update on this ?

AnnaBazmajyan avatar Jul 23 '18 12:07 AnnaBazmajyan

Still having this issue as well. I used @benkahle 's workaround with a little adjustment below. If you tried to submit the form, the hidden input would focus and would mess when using a ReactSelectAsync. Changing the focus when focusing the hidden element did the trick.

Not the best solution, but works until we get an update.

<div className={className}>
    <Select
      ref={(ref) => { this.select = ref; }}
      {...props}
    />
    <input
        tabIndex={-1}
        autoComplete={props.autoComplete}
        value={props.value}
        required={props.required}
        onChange={props.onChange}
        style={{
            opacity: 0,
            width: 0,
            height: 0,
            position: 'absolute',
          }}
        onFocus={() => this.select.focus()}
    />
</div>

brunocramos avatar Jul 31 '18 19:07 brunocramos

Hello -

In an effort to sustain the react-select project going forward, we're closing old issues.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest version.

If you aren't using the latest version of react-select please consider upgrading to see if it resolves any issues you're having.

However, if you feel this issue is still relevant and you'd like us to review it - please leave a comment and we'll do our best to get back to you!

bladey avatar May 28 '20 01:05 bladey

Thanks for the fix, @benkahle and @brunocramos! :)

I ran into an issue where the validation message was displayed over the top of the dropdown:

Image

I tweaked your fix to be this:

<div className={className} style={{position: 'relative'}}>
    <Select
      ref={(ref) => { this.select = ref; }}
      {...props}
    />
    <input
        tabIndex={-1}
        autoComplete={props.autoComplete}
        value={props.value}
        required={props.required}
        onChange={props.onChange}
        style={{
            opacity: 0,
            width: 0,
            height: 0,
            position: 'absolute',
            bottom: 0,
            padding: 0,
            border: 0
          }}
        onFocus={() => this.select.focus()}
    />
</div>

Result:

Image

neoncube2 avatar Oct 05 '25 05:10 neoncube2