-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathApp.js
66 lines (53 loc) · 1.7 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React from 'react';
import './App.css';
import { Form, Item } from 'devextreme-react/form';
import { TextBox } from 'devextreme-react/text-box';
import {
Validator,
RequiredRule,
} from 'devextreme-react/validator';
import validationEngine from "devextreme/ui/validation_engine";
import service from './data.js';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
employee: service.getEmployee()
};
this.lastNameRender = this.lastNameRender.bind(this);
this.photoRender = this.photoRender.bind(this);
}
render() {
return (
<Form formData={this.state.employee} validationGroup="formGroup">
<Item dataField="FirstName" />
<Item dataField="LastName" isRequired={true} render={this.lastNameRender} />
<Item dataField="Photo" render={this.photoRender} />
<Item itemType="button" horizontalAlignment="left"
buttonOptions={{ text: 'Validate', type: 'success', onClick: this.validateClick }} />
</Form>
);
}
lastNameRender(data) {
let valueChanged = (e) => {
data.component.updateData(data.dataField, e.value);
};
return (
<TextBox defaultValue={this.state.employee.LastName} onValueChanged={valueChanged}>
<Validator validationGroup="formGroup">
<RequiredRule message="LastName is required"/>
</Validator>
</TextBox>
);
}
photoRender(data) {
return <img id="formAvatar" src={this.state.employee.Photo} alt="employee" />;
}
validateClick(e) {
let validationResult = validationEngine.validateGroup("formGroup");
if (!validationResult.isValid) {
alert("dxForm is invalid");
}
}
}
export default App;