question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow to disable empty item option for SelectInput

See original GitHub issue

Is your feature request related to a problem? Please describe. I use the SelectInput for a required property, thus it makes no sense to allow to choose the empty option.

I checked the docs and finally also the code and while it is possible to customize the emptyText and emptyValue, it seems there is no way to not render it at all (SelectInput.tsx). It looks like this should be pretty easy to add (however I am of course by no means familiar with the code).

Describe the solution you’d like Add an option to disable rendering the empty option, something like: <SelectInput source="foo" choices={fooChoices} showEmptyOption={false} /> Of course this can simply default to true to ensure it’s not a breaking change

Describe alternatives you’ve considered

  • I can add validate={[required('Foo cannot be empty')]} to at least prevent the user from saving the form without picking a value, but it would be much nicer to not give users the opportunity to empty the input in the first place

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:13
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
ralfaramacommented, Jul 12, 2022

I agree with @weissu42 and @ghost91- and @soullivaneuh that there are many situations where having a spurious blank value makes no sense. There are many scenarios and common ones where one must pick from a set of options and a non-choice is not an acceptable option and the added empty entry (especially as the default) makes for a confusing interface which creates erroneous data by default. Adding a blank entry is inappropriate, confusing and problematic for many scenarios.

Furthermore, requiring the developer to set parameters like “EmptyText” and “EmptyValue” to override a blank default is a solution which introduces problems of its own. When one has a field that requires a value from a referenced column one an implementer is forced to choose between hardcoding a foreign key value or dealing with the case where a user selects an unacceptable blank value. Either case foists problems on an implementer to deal with an undesired artifact of react-admin’s behavior.

4reactions
soullivaneuhcommented, May 19, 2022

I agree with @weissu42 about the non-sens part of having the possibility to select an empty value when the form is required.

What we add before 4.x:

image

What we have now:

image

Adding this option would mean to check that when the showEmptyOption prop is false, developers also provided a valid default value. I don’t think we should as it make the SelectInput API more complicated both for us and for developpers.

@djhi This may be doable with conditional typing. However, I don’t think we should require a default value when we don’t want an empty option. For our use case, we have to ensure the value of the select is selected by a human to avoid mistakes because of the default value.

In a nutshell, the same behavior as for 3.x.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Empty chain not shown as a choice in selectInput in shiny App
The selectize.js library just has no way to allow a blank valued option in the list. The best you can do is use...
Read more >
Create a select list input control — selectInput - R Shiny
The selectize input created from selectizeInput() allows deletion of the selected option even in a single select input, which will return an empty...
Read more >
Virtual Select Input — virtualSelectInput • shinyWidgets
Allow to add new option by searching. disableSelectAll. Disable select all feature of multiple select. disableOptionGroupCheckbox. Disable option group title ...
Read more >
<select>: The HTML Select element - HTML - MDN Web Docs
A Boolean attribute indicating that an option with a non-empty string value must be selected. size. If the control is presented as a...
Read more >
Select | Quasar Framework
pressing BACKSPACE will remove the last option from the selection (when use-input is set the input should be empty). pressing TAB (or SHIFT...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found