forked from FaridSafi/react-native-gifted-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GiftedForm.js
118 lines (101 loc) · 3.08 KB
/
GiftedForm.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import React from 'react';
const GiftedFormManager = require('./GiftedFormManager');
const ContainerMixin = require('./mixins/ContainerMixin');
const WidgetMixin = require('./mixins/WidgetMixin');
const TextInputWidget = require('./widgets/TextInputWidget');
const TextAreaWidget = require('./widgets/TextAreaWidget');
const SwitchWidget = require('./widgets/SwitchWidget');
const SelectWidget = require('./widgets/SelectWidget');
const OptionWidget = require('./widgets/OptionWidget');
const SelectCountryWidget = require('./widgets/SelectCountryWidget');
const DatePickerIOSWidget = require('./widgets/DatePickerIOSWidget');
const ModalWidget = require('./widgets/ModalWidget');
const SubmitWidget = require('./widgets/SubmitWidget');
const SeparatorWidget = require('./widgets/SeparatorWidget');
const GroupWidget = require('./widgets/GroupWidget');
const NoticeWidget = require('./widgets/NoticeWidget');
const ValidationErrorWidget = require('./widgets/ValidationErrorWidget');
const GooglePlacesWidget = require('./widgets/GooglePlacesWidget');
const RowWidget = require('./widgets/RowWidget');
const LoadingWidget = require('./widgets/LoadingWidget');
const HiddenWidget = require('./widgets/HiddenWidget');
const ErrorsWidget = require('./widgets/ErrorsWidget');
const GiftedForm = React.createClass({
mixins: [ ContainerMixin ],
statics: {
TextInputWidget,
TextAreaWidget,
SwitchWidget,
SelectWidget,
OptionWidget,
SelectCountryWidget,
DatePickerIOSWidget,
ModalWidget,
SubmitWidget,
SeparatorWidget,
GroupWidget,
NoticeWidget,
GooglePlacesWidget,
RowWidget,
LoadingWidget,
HiddenWidget,
ValidationErrorWidget,
ErrorsWidget,
},
getDefaultProps() {
return {
isModal: false,
clearOnClose: false,
validators: {},
defaults: {},
openModal: null,
};
},
propTypes: {
isModal: React.PropTypes.bool,
clearOnClose: React.PropTypes.bool,
validators: React.PropTypes.object,
defaults: React.PropTypes.object,
openModal: React.PropTypes.func,
},
componentWillUnmount() {
if (this.props.clearOnClose === true) {
GiftedFormManager.reset(this.props.formName);
}
},
componentWillMount() {
// register validators
for (let key in this.props.validators) {
if (this.props.validators.hasOwnProperty(key)) {
GiftedFormManager.setValidators(this.props.formName, key, this.props.validators[key]);
}
}
// register defaults values
for (let key in this.props.defaults) {
if (this.props.defaults.hasOwnProperty(key)) {
GiftedFormManager.updateValueIfNotSet(this.props.formName, key, this.props.defaults[key]);
}
}
},
render() {
return this._renderContainerView();
},
});
var GiftedFormModal = React.createClass({
mixins: [ ContainerMixin ],
getDefaultProps() {
return {
isModal: true,
};
},
propTypes: {
isModal: React.PropTypes.bool,
},
render() {
return this._renderContainerView();
},
});
module.exports = {
GiftedForm, GiftedFormModal, GiftedFormManager,
WidgetMixin,
};