Material-ui: Select does not allow for a required attribute

Created on 13 Jun 2018  路  5Comments  路  Source: mui-org/material-ui

@material-ui/core/Select does not allow for a required attribute like @material-ui/core/TextField

  • [x] This is a v1.x issue (v0.x is no longer maintained).
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Should be able to add required attribute to the <Select> input and it should:

  • Add * to label
  • Add required attribute to the rendered <input> tag

Current Behavior

Currently no support for required attribute on <Select> tags

Steps to Reproduce (for bugs)

https://codesandbox.io/s/qx4x1w8qlj

  1. Add <Select> input with required attribute

Context

Would like <Select> inputs to act like <TextField> inputs to make UI consistent

Your Environment

| Tech | Version |
|--------------|---------|
| Material-UI | v1.0.0 |
| React | v16.3.2 |
| browser | Chrome |

Select docs

Most helpful comment

Well it's a shame because it would be nice to be able to still have the chance to use the custom select look and feel without losing the HTML5 validation.

All 5 comments

@oliviertassinari looks like the non-native solution uses a type=hidden input so the required validation won't really run unfortunately. Attempting to change it to type=text in inputProps results in the following error:

Warning: Failed prop type: You provided a value prop to a form field without an onChange handler.

@mciparelli If you are looking for the native require validation logic, use the native implementation of the select.

Well it's a shame because it would be nice to be able to still have the chance to use the custom select look and feel without losing the HTML5 validation.

@mciparelli Let us know if you find a way to change the implementation to get this done. But I have some doubt that we can achieve it.

@t-lock The inputRef prop should solve your issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FranBran picture FranBran  路  3Comments

ghost picture ghost  路  3Comments

rbozan picture rbozan  路  3Comments

ericraffin picture ericraffin  路  3Comments

finaiized picture finaiized  路  3Comments