Talking about react implement input box

Source: Internet
Author: User
Tags regular expression

Features to be implemented by the component:

1, custom Label and input box of the placeholder content;

2, the input content does not conform to the regular expression request, the input box is marked red, conforms to the time standard green;

3, click the Clear button, the button disappears and clears the contents of the input box;

4, open to the outside 3 methods: Gets, sets, deletes the contents of the input box (trim).


Inputbox.html:

<! DOCTYPE html>


INPUTBOX.JSX:

var grades = [{team: "Team1", Name: "Alice", grade:80}, {team: "Team1", Name: "Bruce", grade:90}, {team: "Team1", NA Me: "Cindy", grade:50}, {team: "Team2", Name: "David", grade:40}, {team: "Team2", Name: "Emy", grade:60}, {team: "Te
AM2 ", Name:" Fruid ", grade:70}];
		var Filterbox = React.createclass ({getinitialstate:function () {return {inputtext: "", Showpassingonly:false
	}; }, Filter:function (Inputtext, showpassingonly) {this.setstate ({inputtext:inputtext, Showpassingonly:showpass
	Ingonly}); }, Render:function () {return (<div> <searchbox Oninput={this.filter} inputtext={this.state.inputtext } showpassingonly={this.state.showpassingonly}/> <gradelist Grades={this.props.grades} inputText={
	This.state.inputText} showpassingonly={this.state.showpassingonly}/> </div>);
}
}); var searchbox = React.createclass ({filter:function () {this.props.onInput (This.refs.input.value, This.refs.che Ckbox.checked); }, Render:function () {return (<form> <input id= "text" type= "text" ref= "input" placeholder= "sreaching ... "Onchange={this.filter} value={this.props.inputtext}/><br/> <input type=" checkbox "ref=" checkbox "
	Checked={this.props.showpassingonly} onchange={this.filter}/>only Show passing grades </form>);
}
});
		var gradelist = React.createclass ({render:function () {var rows = [];
		var teams = [];  This.props.grades.forEach (function (grade, index) {if (Grade.name.toLowerCase (). IndexOf (This.props.inputText) = =-1 | |
			This.props.showPassingOnly && Grade.grade <) return;
				if (Teams.indexof (grade.team) = =-1) {Rows.push (<team Team={grade.team} key={"team" + index}></team>);
			Teams.push (Grade.team);
		} rows.push (<grade name={grade.name} grade={grade.grade} key={"Grade" + index}></grade>);
		}.bind (this)); if (Rows.length = = 0) rows.push (<tr key={"NomatcheS "}><td colspan=" 2 ">no matches!</td></tr>); Return (<table> <thead> <tr> <th>Name</th> &LT;TH&GT;GRADE&LT;/TH&G
					T
	</tr> </thead> <tbody> {rows} </tbody> </table>);
}
}); var Team = React.createclass ({render:function () {return (<tr> <td colspan= "2" >{this.props.team}&
	Lt;/td> </tr>);
}
});
				var Grade = React.createclass ({render:function ()} {return (<tr> <td>{this.props.name}</td>
	<td>{this.props.grade}</td> </tr>);
}
}); Reactdom.render (<filterbox grades={grades}/>, document.getElementById (' Filterbox '));
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.