I have got a register form which sends request with the first and last name and works fine. But, when a user enters whitespace it considers it as a valid input. The validation errors are sent from the api's response where a blank input gives an error. I tried to trim the firstname in submit() thinking that it it has spaces, it will remove it and consider as a blank input. But this doesnt seem to work. How can I implement the logic for it to trim the whitespace and not allow it.
export default class Signup extends Form {
constructor(props, context) {
super(props, context);
this.state = {
firstName: '',
lastName: '',
};
this.handleChange = this.handleChange.bind(this);
}
submit() {
let firstName=this.state.firstName.trim();
return this.app.register({
firstName: firstName,
lastName: this.state.lastName,
}).then(account => success())
.catch(e => {
this.setState({ error: `signup_form_error_${e}` });
})
}
handleChange(event) {
this.setState({
[event.target.name]: event.target.value
})
}
render(props, state) {
return <form onSubmit={this.form.submit} name="signup" noValidate>
<input type="text" name="firstName" value={this.state.firstName} onChange={this.handleChange} />
<input type="text" name="lastName" value={this.state.lastName} onChange={this.handleChange} />
<div class="s72-buttons">
<button type="submit"</button>
</div>
</form>;
}
}