react-form-component icon indicating copy to clipboard operation
react-form-component copied to clipboard

Select without "All" default

Open listvin opened this issue 1 year ago • 1 comments

I want my Select input to be selection only from list with following code:

return <Select
        mandatory={true}
        options={["a","b"]}
        name={"ab"}
        label={"choose a or b"}
/>

But I am getting selection from All, a and b. I expect mandatory flag to prevent "All" or similar things to be available.

I noticed that if I supply "xx" to placeholder user gets options xx, a and b. However from code perspective I see values "","a","b". Supplying initialValue does not help -- user can still switch to placeholder value (from his perspective and "" from code perspective)

Am I missing something?

Thank you

listvin avatar Sep 11 '24 11:09 listvin

@listvin You have to set field as mandatory to disable "All" option from selecting. But pointing madnatory fields happens on Form component level, not the input itself. Here is the example:

<Form fields={['ab']} mandatory={['ab']}>
    <Select
      options={["a","b"]}
      name="ab"
      label={"choose a or b"}
    />
</Form>

firflant avatar Nov 24 '24 12:11 firflant