Commit 51240889 authored by Sakthivel G's avatar Sakthivel G
Browse files

refactor: add invalid error message for email field

Showing with 56 additions and 14 deletions
+56 -14
...@@ -2344,6 +2344,11 @@ div.tooltip { ...@@ -2344,6 +2344,11 @@ div.tooltip {
margin-right: 3em; margin-right: 3em;
} }
.invalid-input {
font-size: 0.875rem;
color: red;
}
/* Admin pannel css starts */ /* Admin pannel css starts */
.admin-pannel { .admin-pannel {
......
...@@ -12,7 +12,9 @@ class Input extends Component { ...@@ -12,7 +12,9 @@ class Input extends Component {
this.state = { this.state = {
fieldType: "", fieldType: "",
language: "en", language: "en",
isInvalid: false,
}; };
this.validateEmailInput = this.validateEmailInput.bind(this);
} }
componentDidMount() { componentDidMount() {
...@@ -34,6 +36,21 @@ class Input extends Component { ...@@ -34,6 +36,21 @@ class Input extends Component {
} }
} }
validateEmailInput = (e) => {
let inputData = e.target.value;
//eslint-disable-next-line
let allowedFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (inputData.match(allowedFormat)) {
this.setState({
isInvalid: false,
});
} else {
this.setState({
isInvalid: true,
});
}
};
render() { render() {
// console.log(this.props.field.fieldType); // console.log(this.props.field.fieldType);
// strings.setLanguage( // strings.setLanguage(
...@@ -54,20 +71,40 @@ class Input extends Component { ...@@ -54,20 +71,40 @@ class Input extends Component {
</span> </span>
)} )}
</label> </label>
<input {this.props.field.fieldType !==
type={ LANG.FIELD_TYPES.email.toLowerCase() && (
this.props.field.fieldType === <input
LANG.FIELD_TYPES.numeric type={
? "number" this.props.field.fieldType === LANG.FIELD_TYPES.numeric
: this.state.fieldType ? "number"
} : this.state.fieldType
id={"field-" + this.props.field.order} }
name={"field_" + this.props.field.order} id={"field-" + this.props.field.order}
className="form-control" name={"field_" + this.props.field.order}
placeholder="Type here" className="form-control"
autoComplete="off" placeholder="Type here"
/> autoComplete="off"
/>
)}
{this.props.field.fieldType ===
LANG.FIELD_TYPES.email.toLowerCase() && (
<div className="">
<input
type="email"
id={"field-" + this.props.field.order}
name={"field_" + this.props.field.order}
className="form-control"
placeholder="Type here"
autoComplete="off"
onChange={this.validateEmailInput}
/>
{this.state.isInvalid && (
<p className="invalid-input">Invalid email!</p>
)}
</div>
)}
</div> </div>
</div> </div>
); );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment