Skip to content

Commit f25c38f

Browse files
authored
Merge pull request #8887 from Expensify/cmartins-rmIsFormInput
Remove isFormInput prop
2 parents a2f8cf9 + 424a96a commit f25c38f

File tree

9 files changed

+15
-102
lines changed

9 files changed

+15
-102
lines changed

FORMS.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,27 +187,24 @@ function onSubmit(values) {
187187
label="Routing number"
188188
inputID="routingNumber"
189189
maxLength={8}
190-
isFormInput
191190
shouldSaveDraft
192191
/>
193192
</View>
194193
<TextInput
195194
label="Account number"
196195
inputID="accountNumber"
197196
containerStyles={[styles.mt4]}
198-
isFormInput
199197
/>
200198
</Form>
201199
```
202200

203201
### Props provided to Form inputs
204202

205-
The following props are available to form inputs:
203+
The following prop is available to form inputs:
206204

207205
- inputID: An unique identifier for the input.
208-
- isFormInput: A flag that indicates that this input is being used with Form.js.
209206

210-
Form.js will automatically provide the following props to any input flagged with the isFormInput prop.
207+
Form.js will automatically provide the following props to any input with the inputID prop.
211208

212209
- ref: A React ref that must be attached to the input.
213210
- defaultValue: The input default value.

src/components/AddressSearch.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,15 @@ import styles from '../styles/styles';
99
import TextInput from './TextInput';
1010
import Log from '../libs/Log';
1111
import * as GooglePlacesUtils from '../libs/GooglePlacesUtils';
12-
import * as FormUtils from '../libs/FormUtils';
1312

1413
// The error that's being thrown below will be ignored until we fork the
1514
// react-native-google-places-autocomplete repo and replace the
1615
// VirtualizedList component with a VirtualizedList-backed instead
1716
LogBox.ignoreLogs(['VirtualizedLists should never be nested']);
1817

1918
const propTypes = {
20-
/** Indicates that the input is being used with the Form component */
21-
isFormInput: PropTypes.bool,
22-
23-
/**
24-
* The ID used to uniquely identify the input
25-
*
26-
* @param {Object} props - props passed to the input
27-
* @returns {Object} - returns an Error object if isFormInput is supplied but inputID is falsey or not a string
28-
*/
29-
inputID: props => FormUtils.validateInputIDProps(props),
19+
/** The ID used to uniquely identify the input in a Form */
20+
inputID: PropTypes.string,
3021

3122
/** Saves a draft of the input value when used in a form */
3223
shouldSaveDraft: PropTypes.bool,
@@ -59,7 +50,6 @@ const propTypes = {
5950
};
6051

6152
const defaultProps = {
62-
isFormInput: false,
6353
inputID: undefined,
6454
shouldSaveDraft: false,
6555
onBlur: () => {},
@@ -174,13 +164,12 @@ const AddressSearch = (props) => {
174164
hint: props.hint,
175165
value: props.value,
176166
defaultValue: props.defaultValue,
177-
isFormInput: props.isFormInput,
178167
inputID: props.inputID,
179168
shouldSaveDraft: props.shouldSaveDraft,
180169
onBlur: props.onBlur,
181170
autoComplete: 'off',
182171
onInputChange: (text) => {
183-
if (props.isFormInput) {
172+
if (props.inputID) {
184173
props.onInputChange(text);
185174
} else {
186175
props.onInputChange({street: text});

src/components/CheckboxWithLabel.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import styles from '../styles/styles';
66
import Checkbox from './Checkbox';
77
import Text from './Text';
88
import InlineErrorText from './InlineErrorText';
9-
import * as FormUtils from '../libs/FormUtils';
109

1110
const propTypes = {
1211
/** Whether the checkbox is checked */
@@ -27,29 +26,20 @@ const propTypes = {
2726
/** Error text to display */
2827
errorText: PropTypes.string,
2928

30-
/** Indicates that the input is being used with the Form component */
31-
isFormInput: PropTypes.bool,
32-
3329
/** The default value for the checkbox */
3430
defaultValue: PropTypes.bool,
3531

3632
/** React ref being forwarded to the Checkbox input */
3733
forwardedRef: PropTypes.func,
3834

39-
/**
40-
* The ID used to uniquely identify the input
41-
*
42-
* @param {Object} props - props passed to the input
43-
* @returns {Object} - returns an Error object if isFormInput is supplied but inputID is falsey or not a string
44-
*/
45-
inputID: props => FormUtils.validateInputIDProps(props),
35+
/** The ID used to uniquely identify the input in a Form */
36+
inputID: PropTypes.string,
4637

4738
/** Saves a draft of the input value when used in a form */
4839
shouldSaveDraft: PropTypes.bool,
4940
};
5041

5142
const defaultProps = {
52-
isFormInput: false,
5343
inputID: undefined,
5444
style: [],
5545
label: undefined,
@@ -86,7 +76,6 @@ const CheckboxWithLabel = (props) => {
8676
label={props.label}
8777
hasError={Boolean(props.errorText)}
8878
forwardedRef={props.forwardedRef}
89-
isFormInput={props.isFormInput}
9079
inputID={props.inputID}
9180
shouldSaveDraft={props.shouldSaveDraft}
9281
/>

src/components/Form.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ class Form extends React.Component {
135135
});
136136
}
137137

138-
// We check if the child has the isFormInput prop.
138+
// We check if the child has the inputID prop.
139139
// We don't want to pass form props to non form components, e.g. View, Text, etc
140-
if (!child.props.isFormInput) {
140+
if (!child.props.inputID) {
141141
return child;
142142
}
143143

src/components/Picker/index.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import BasePicker from './BasePicker';
66
import Text from '../Text';
77
import styles from '../../styles/styles';
88
import InlineErrorText from '../InlineErrorText';
9-
import * as FormUtils from '../../libs/FormUtils';
109

1110
const propTypes = {
1211
/** Picker label */
@@ -24,16 +23,8 @@ const propTypes = {
2423
/** Customize the Picker container */
2524
containerStyles: PropTypes.arrayOf(PropTypes.object),
2625

27-
/** Indicates that the input is being used with the Form component */
28-
isFormInput: PropTypes.bool,
29-
30-
/**
31-
* The ID used to uniquely identify the input
32-
*
33-
* @param {Object} props - props passed to the input
34-
* @returns {Object} - returns an Error object if isFormInput is supplied but inputID is falsey or not a string
35-
*/
36-
inputID: props => FormUtils.validateInputIDProps(props),
26+
/** The ID used to uniquely identify the input in a Form */
27+
inputID: PropTypes.string,
3728

3829
/** Saves a draft of the input value when used in a form */
3930
shouldSaveDraft: PropTypes.bool,
@@ -44,7 +35,6 @@ const defaultProps = {
4435
isDisabled: false,
4536
errorText: '',
4637
containerStyles: [],
47-
isFormInput: false,
4838
inputID: undefined,
4939
shouldSaveDraft: false,
5040
value: undefined,

src/components/StatePicker.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
44
import {CONST} from 'expensify-common/lib/CONST';
55
import Picker from './Picker';
66
import withLocalize, {withLocalizePropTypes} from './withLocalize';
7-
import * as FormUtils from '../libs/FormUtils';
87

98
const STATES = _.map(CONST.STATES, ({stateISO}) => ({
109
value: stateISO,
@@ -21,16 +20,8 @@ const propTypes = {
2120
/** The value that needs to be selected */
2221
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
2322

24-
/** Indicates that the input is being used with the Form component */
25-
isFormInput: PropTypes.bool,
26-
27-
/**
28-
* The ID used to uniquely identify the input
29-
*
30-
* @param {Object} props - props passed to the input
31-
* @returns {Object} - returns an Error object if isFormInput is supplied but inputID is falsey or not a string
32-
*/
33-
inputID: props => FormUtils.validateInputIDProps(props),
23+
/** The ID used to uniquely identify the input in a Form */
24+
inputID: PropTypes.string,
3425

3526
/** Saves a draft of the input value when used in a form */
3627
shouldSaveDraft: PropTypes.bool,
@@ -53,7 +44,6 @@ const defaultProps = {
5344
defaultValue: undefined,
5445
errorText: '',
5546
shouldSaveDraft: false,
56-
isFormInput: false,
5747
inputID: undefined,
5848
onBlur: () => {},
5949
};
@@ -69,7 +59,6 @@ const StatePicker = forwardRef((props, ref) => (
6959
label={props.label || props.translate('common.state')}
7060
errorText={props.errorText}
7161
onBlur={props.onBlur}
72-
isFormInput={props.isFormInput}
7362
shouldSaveDraft={props.shouldSaveDraft}
7463
/>
7564
));

src/components/TextInput/baseTextInputPropTypes.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import PropTypes from 'prop-types';
2-
import * as FormUtils from '../../libs/FormUtils';
32

43
const propTypes = {
54
/** Input label */
@@ -57,16 +56,8 @@ const propTypes = {
5756
prefixCharacter: PropTypes.string,
5857

5958
/** Form props */
60-
/** Indicates that the input is being used with the Form component */
61-
isFormInput: PropTypes.bool,
62-
63-
/**
64-
* The ID used to uniquely identify the input
65-
*
66-
* @param {Object} props - props passed to the input
67-
* @returns {Object} - returns an Error object if isFormInput is supplied but inputID is falsey or not a string
68-
*/
69-
inputID: props => FormUtils.validateInputIDProps(props),
59+
/** The ID used to uniquely identify the input in a Form */
60+
inputID: PropTypes.string,
7061

7162
/** Saves a draft of the input value when used in a form */
7263
shouldSaveDraft: PropTypes.bool,
@@ -76,7 +67,6 @@ const propTypes = {
7667
};
7768

7869
const defaultProps = {
79-
isFormInput: false,
8070
label: '',
8171
name: '',
8272
errorText: '',

src/libs/FormUtils.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/stories/Form.stories.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,24 @@ const Template = (args) => {
4242
<TextInput
4343
label="Routing number"
4444
inputID="routingNumber"
45-
isFormInput
4645
shouldSaveDraft
4746
/>
4847
</View>
4948
<TextInput
5049
label="Account number"
5150
inputID="accountNumber"
5251
containerStyles={[styles.mt4]}
53-
isFormInput
5452
/>
5553
<AddressSearch
5654
label="Street"
5755
inputID="street"
5856
containerStyles={[styles.mt4]}
5957
hint="No PO box"
60-
isFormInput
6158
/>
6259
<DatePicker
6360
label="Date of birth"
6461
inputID="dob"
6562
containerStyles={[styles.mt4]}
66-
isFormInput
6763
/>
6864
<View>
6965
<Picker
@@ -85,7 +81,6 @@ const Template = (args) => {
8581
value: 'apple',
8682
},
8783
]}
88-
isFormInput
8984
/>
9085
</View>
9186
<Picker
@@ -106,19 +101,16 @@ const Template = (args) => {
106101
value: 'apple',
107102
},
108103
]}
109-
isFormInput
110104
/>
111105
<View style={styles.mt4}>
112106
<StatePicker
113107
inputID="pickState"
114108
shouldSaveDraft
115-
isFormInput
116109
/>
117110
</View>
118111
<CheckboxWithLabel
119112
inputID="checkbox"
120113
style={[styles.mb4, styles.mt5]}
121-
isFormInput
122114
shouldSaveDraft
123115
LabelComponent={() => (
124116
<Text>I accept the Expensify Terms of Service</Text>
@@ -148,7 +140,6 @@ const WithNativeEventHandler = (args) => {
148140
label="Routing number"
149141
inputID="routingNumber"
150142
onChangeText={setLog}
151-
isFormInput
152143
shouldSaveDraft
153144
/>
154145
<Text>

0 commit comments

Comments
 (0)