MCPcopy
hub / github.com/react-component/form / getFieldProps

Function getFieldProps

src/createBaseForm.js:225–312  ·  view source on GitHub ↗
(name, usersFieldOption = {})

Source from the content-addressed store, hash-verified

223 },
224
225 getFieldProps(name, usersFieldOption = {}) {
226 if (!name) {
227 throw new Error('Must call `getFieldProps` with valid name string!');
228 }
229 if (process.env.NODE_ENV !== 'production') {
230 warning(
231 this.fieldsStore.isValidNestedFieldName(name),
232 `One field name cannot be part of another, e.g. \`a\` and \`a.b\`. Check field: ${name}`,
233 );
234 warning(
235 !('exclusive' in usersFieldOption),
236 '`option.exclusive` of `getFieldProps`|`getFieldDecorator` had been remove.',
237 );
238 }
239
240 delete this.clearedFieldMetaCache[name];
241
242 const fieldOption = {
243 name,
244 trigger: DEFAULT_TRIGGER,
245 valuePropName: 'value',
246 validate: [],
247 ...usersFieldOption,
248 };
249
250 const {
251 rules,
252 trigger,
253 validateTrigger = trigger,
254 validate,
255 } = fieldOption;
256
257 const fieldMeta = this.fieldsStore.getFieldMeta(name);
258 if ('initialValue' in fieldOption) {
259 fieldMeta.initialValue = fieldOption.initialValue;
260 }
261
262 const inputProps = {
263 ...this.fieldsStore.getFieldValuePropValue(fieldOption),
264 ref: this.getCacheBind(name, `${name}__ref`, this.saveRef),
265 };
266 if (fieldNameProp) {
267 inputProps[fieldNameProp] = formName ? `${formName}_${name}` : name;
268 }
269
270 const validateRules = normalizeValidateRules(
271 validate,
272 rules,
273 validateTrigger,
274 );
275 const validateTriggers = getValidateTriggers(validateRules);
276 validateTriggers.forEach(action => {
277 if (inputProps[action]) return;
278 inputProps[action] = this.getCacheBind(
279 name,
280 action,
281 this.onCollectValidate,
282 );

Callers 15

renderMethod · 0.85
renderMethod · 0.85
renderMethod · 0.85
renderMethod · 0.85
renderMethod · 0.85
renderMethod · 0.85
renderMethod · 0.85
renderMethod · 0.85
file-input.jsFile · 0.85
renderMethod · 0.85
across-router.jsFile · 0.85
start-end-date.jsFile · 0.85

Calls 7

normalizeValidateRulesFunction · 0.90
getValidateTriggersFunction · 0.90
getFieldMetaMethod · 0.80
setFieldMetaMethod · 0.80
getFieldMethod · 0.80

Tested by 8

renderMethod · 0.68
renderMethod · 0.68
renderMethod · 0.68
renderMethod · 0.68
renderMethod · 0.68
renderMethod · 0.68
renderMethod · 0.68
renderMethod · 0.68