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.

How to underline the TextField only if an error occurs ?

See original GitHub issue

TextFields in v0.20.0 used to have an “ErrorText” property, which was very useful to display an error under a textfield and underline it in red at the same time.

<TextField
      hintText="Hint Text"
      errorText="This field is required"
      floatingLabelText="Floating Label Text"
/>

However, TextFields in material-ui@next don’t have that property. In order to display an error and underline in red, a much more complex alternative is used

<FormControl className={classes.formControl} error aria-describedby="name-error-text">
          <InputLabel htmlFor="name-error">Name</InputLabel>
          <Input id="name-error" value={this.state.name} onChange={this.handleChange} />
          <FormHelperText id="name-error-text">Error</FormHelperText>
</FormControl>

Is this the only option ? Is there any other way to achieve it ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
JCofmancommented, Mar 22, 2018

@ras24 I think there should be an error boolean prop which you can set. Which changes the color of the helperText to red <TextField error />

1reaction
ras24commented, Mar 22, 2018

@ArthurAttout I tried using material-ui@next

  <TextField
       className={classes.textField}
       name='name'
       label='Name'
       placeholder='Type your name'
       value={this.state.name}
       onChange={this.onChange}
       helperText={this.state.error}
  />

If error occur, helperText just shown error messege with the gray color not a red color.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to underline the TextField only if an error occurs ? #10622
TextFields in v0.20.0 used to have an "ErrorText" property, which was very useful to display an error under a textfield and underline it...
Read more >
Is it possible to underline text on JTextField?If Yes, How?
Yes - by adjusting the Font attributes of the component. Font font = textField.getFont(); Map attributes = font.
Read more >
Text Field w/Indent Underline Issue - SAP Community
Hello, I have a text field in the report which indents dynamically; this field is underlined. I need the underline to start where...
Read more >
TextField - FlutterFlow Docs
By default, a TextField is only one line. So when you type in a long text that won't fit in one line, you'll...
Read more >
Text in Compose - Jetpack - Android Developers
TextField allows users to enter and modify text. There are two levels of TextField implementations: TextField is the Material Design implementation. We ...
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