Skip to content

Commit 80de300

Browse files
committed
Update readme.
1 parent 49ff182 commit 80de300

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

Readme.md

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,19 @@ Your component must [provide a theme](http://www.material-ui.com/#/get-started/u
4444
````javascript
4545

4646
import React from 'react';
47-
import RaisedButton from 'material-ui/RaisedButton';
47+
import Button from '@material-ui/core/Button';
4848
import { ValidatorForm, TextValidator} from 'react-material-ui-form-validator';
4949

5050
class MyForm extends React.Component {
5151

52-
constructor(props) {
53-
super(props);
54-
this.state = {};
55-
this.handleChange = this.handleChange.bind(this);
56-
}
52+
state = {}
5753

58-
handleChange(event) {
54+
handleChange = (event) => {
5955
const email = event.target.value;
6056
this.setState({ email });
6157
}
6258

63-
handleSubmit() {
59+
handleSubmit = () => {
6460
// your submit logic
6561
}
6662

@@ -73,14 +69,14 @@ class MyForm extends React.Component {
7369
onError={errors => console.log(errors)}
7470
>
7571
<TextValidator
76-
floatingLabelText="Email"
72+
label="Email"
7773
onChange={this.handleChange}
7874
name="email"
7975
value={email}
8076
validators={['required', 'isEmail']}
8177
errorMessages={['this field is required', 'email is not valid']}
8278
/>
83-
<RaisedButton type="submit" />
79+
<Button type="submit">Submit</Button>
8480
</ValidatorForm>
8581
);
8682
}
@@ -92,20 +88,14 @@ You can add your custom rules:
9288
````javascript
9389

9490
import React from 'react';
95-
import RaisedButton from 'material-ui/RaisedButton';
91+
import Button from '@material-ui/core/Button';
9692
import { ValidatorForm, TextValidator} from 'react-material-ui-form-validator';
9793

9894
class ResetPasswordForm extends React.Component {
9995

100-
constructor(props) {
101-
super(props);
102-
this.state = {
103-
user: {},
104-
};
105-
this.handleChange = this.handleChange.bind(this);
106-
}
96+
state = { user: {} };
10797

108-
componentWillMount() {
98+
componentDidMount() {
10999
// custom rule will have name 'isPasswordMatch'
110100
ValidatorForm.addValidationRule('isPasswordMatch', (value) => {
111101
if (value !== this.state.user.password) {
@@ -115,13 +105,13 @@ class ResetPasswordForm extends React.Component {
115105
});
116106
}
117107

118-
handleChange(event) {
108+
handleChange = (event) => {
119109
const { user } = this.state;
120110
user[event.target.name] = event.target.value;
121111
this.setState({ user });
122112
}
123113

124-
handleSubmit() {
114+
handleSubmit = () => {
125115
// your submit logic
126116
}
127117

@@ -133,7 +123,7 @@ class ResetPasswordForm extends React.Component {
133123
onSubmit={this.handleSubmit}
134124
>
135125
<TextValidator
136-
floatingLabelText="Password"
126+
label="Password"
137127
onChange={this.handleChange}
138128
name="password"
139129
type="password"
@@ -142,15 +132,15 @@ class ResetPasswordForm extends React.Component {
142132
value={user.password}
143133
/>
144134
<TextValidator
145-
floatingLabelText="Repeat password"
135+
label="Repeat password"
146136
onChange={this.handleChange}
147137
name="repeatPassword"
148138
type="password"
149139
validators={['isPasswordMatch', 'required']}
150140
errorMessages={['password mismatch', 'this field is required']}
151141
value={user.repeatPassword}
152142
/>
153-
<RaisedButton type="submit" />
143+
<Button type="submit">Submit</Button>
154144
</ValidatorForm>
155145
);
156146
}
@@ -160,10 +150,20 @@ class ResetPasswordForm extends React.Component {
160150
Currently material-ui [doesn't support](https://github.com/callemall/material-ui/issues/3771) error messages for switches, but you can easily add your own:
161151
````javascript
162152
import React from 'react';
163-
import { red300 } from 'material-ui/styles/colors';
164-
import Checkbox from 'material-ui/Checkbox';
153+
import red from '@material-ui/core/colors/red';
154+
import Checkbox from '@material-ui/core/Checkbox';
165155
import { ValidatorComponent } from 'react-material-ui-form-validator';
166156
157+
const red300 = red['500'];
158+
159+
const style = {
160+
right: 0,
161+
fontSize: '12px',
162+
color: red300,
163+
position: 'absolute',
164+
marginTop: '-25px',
165+
};
166+
167167
class CheckboxValidatorElement extends ValidatorComponent {
168168
169169
render() {
@@ -187,14 +187,6 @@ class CheckboxValidatorElement extends ValidatorComponent {
187187
return null;
188188
}
189189
190-
const style = {
191-
right: 0,
192-
fontSize: '12px',
193-
color: red300,
194-
position: 'absolute',
195-
marginTop: '-25px',
196-
};
197-
198190
return (
199191
<div style={style}>
200192
{this.getErrorMessage()}
@@ -206,7 +198,7 @@ class CheckboxValidatorElement extends ValidatorComponent {
206198
export default CheckboxValidatorElement;
207199
````
208200
````javascript
209-
componentWillMount() {
201+
componentDidMount() {
210202
ValidatorForm.addValidationRule('isTruthy', value => value);
211203
}
212204
...
@@ -215,7 +207,7 @@ export default CheckboxValidatorElement;
215207
validators=['isTruthy']
216208
errorMessages=['this field is required']
217209
checked={value}
218-
value={value} <---- you must provide this prop, it will be used only for validation
210+
value={value} // <---- you must provide this prop, it will be used only for validation
219211
/>
220212
````
221213

0 commit comments

Comments
 (0)