Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

Material-UI hide input & add min/max character length

I have a text input field and a sign up button. Since it's a password the user is going to enter in the field I want the input to be hidden. Any ideas on how to implement this feature?

I also want the field to be sort of disabled if the length of the password is less than 5 characters and longer than 12. (UPDATE: SOLVED IN BACKEND!)

I would be able to figure out at least the min and max length if I was using ''normal'' frontend styling, but I'm trying out Material UI for the first time and I can't really find the right information on how to make this work now.

<TextField
 id="Password"
 label="Password"
 value={password}    
 onChange={handlePasswordChange}
 variant="outlined"
/>

<Button variant="contained" color="primary">
   Sign up!
 </Button>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Add the type attribute like this:

<TextField
 id="Password"
 label="Password"
 type="password"
 value={password}    
 onChange={handlePasswordChange}
 variant="outlined"
/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...