Material Ui - Add required attribute to a TextField in "select" mode

Bichoy Messiha picture Bichoy Messiha · Sep 2, 2018 · Viewed 14.8k times · Source

I am trying to make "required" a TextField in select mode. I tried to add required prop like in this snippet, but this does not block the submit event if I haven't select anything. Although it adds the '*' to the label.

Please check this sandbox

UPDATE: (Clarification really) I am talking about html5 validation. In the sandbox example there are Select and Text fields, setting the text field as required will block the submit event and displays a native html5 error saying "this field is required", this is not the case if the field is "select".

Answer

Bichoy Messiha picture Bichoy Messiha · Sep 2, 2018

Material Ui provides another component Native Select to handle this kind of native validation.

Please check this example

Edit Material demo