From 17c450ee0ad7f2cc16e2631823f7ec30711668f8 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Fri, 30 Sep 2016 17:17:03 +0800 Subject: [PATCH] chore: replace error with warning --- package.json | 5 +++-- src/createBaseForm.js | 19 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index cf60532e..ec0a1187 100644 --- a/package.json +++ b/package.json @@ -57,9 +57,10 @@ "lint" ], "dependencies": { - "babel-runtime": "6.x", "async-validator": "1.x", + "babel-runtime": "6.x", "dom-scroll-into-view": "1.x", - "hoist-non-react-statics": "1.x" + "hoist-non-react-statics": "1.x", + "warning": "^3.0.0" } } diff --git a/src/createBaseForm.js b/src/createBaseForm.js index 94d8e660..911c594b 100644 --- a/src/createBaseForm.js +++ b/src/createBaseForm.js @@ -8,6 +8,7 @@ import { flatFieldNames, clearVirtualField, } from './utils'; import AsyncValidator from 'async-validator'; +import warning from 'warning'; const DEFAULT_VALIDATE_TRIGGER = 'onChange'; const DEFAULT_TRIGGER = DEFAULT_VALIDATE_TRIGGER; @@ -126,22 +127,20 @@ function createBaseForm(option = {}, mixins = []) { const originalProps = fieldElem.props; if (process.env.NODE_ENV !== 'production') { const valuePropName = fieldMeta.valuePropName; - if (valuePropName in originalProps) { - throw new Error( - `\`getFieldDecorator\` will override \`${valuePropName}\`, ` + + warning( + !(valuePropName in originalProps), + `\`getFieldDecorator\` will override \`${valuePropName}\`, ` + `so please don't set \`${valuePropName}\` directly ` + `and use \`setFieldsValue\` to set it.` - ); - } + ); const defaultValuePropName = `default${valuePropName[0].toUpperCase()}${valuePropName.slice(1)}`; - if (defaultValuePropName in originalProps) { - throw new Error( - `\`${defaultValuePropName}\` is invalid ` + + warning( + !(defaultValuePropName in originalProps), + `\`${defaultValuePropName}\` is invalid ` + `for \`getFieldDecorator\` will set \`${valuePropName}\`,` + ` please use \`option.initialValue\` instead.` - ); - } + ); } fieldMeta.originalProps = originalProps; fieldMeta.ref = fieldElem.ref;