diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index f4f13a38e..4a9d1f93d 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -19,7 +19,7 @@ - 🔥🔥🔥 [Descriptions](https://antdv.com/components/descriptions/) Display multiple read-only fields in groups. - 🔥🔥🔥 [PageHeader](https://antdv.com/components/page-header/) can be used to declare the topic of the page, display important information about the page that the user is concerned about, and carry the operation items related to the current page. - 🔥🔥🔥 [Result](https://antdv.com/components/result) is used to feedback the processing results of a series of operation tasks. - - 🔥🔥🔥 [NewForm](https://antdv.com/components/n-form) Form components that use v-model for automatic validation are more concise than v-decorator forms. + - 🔥🔥🔥 [FormModel](https://antdv.com/components/form-model) Form components that use v-model for automatic validation are more concise than v-decorator forms. - 🔥 Descriptions supports vertical layout. - 🔥 Progress.Circle supports gradient colors. - 🔥 Progress.Line supports gradient colors. diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index f7c6390cc..f0ba5a49b 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -19,7 +19,7 @@ - 🔥🔥🔥 [Descriptions](https://antdv.com/components/descriptions-cn/) 成组展示多个只读字段。 - 🔥🔥🔥 [PageHeader](https://antdv.com/components/page-header-cn/) 可用于声明页面主题、展示用户所关注的页面重要信息,以及承载与当前页相关的操作项。 - 🔥🔥🔥 [Result](https://antdv.com/components/result) 用于反馈一系列操作任务的处理结果。 - - 🔥🔥🔥 [NewForm](https://antdv.com/components/n-form) 使用 v-model 进行自动校验的表单组件,相较于 v-decorator 形式的表单,更加简洁。 + - 🔥🔥🔥 [FormModel](https://antdv.com/components/form-model) 使用 v-model 进行自动校验的表单组件,相较于 v-decorator 形式的表单,更加简洁。 - 🔥 Descriptions 支持垂直布局。 - 🔥 Progress.Circle 支持渐变色。 - 🔥 Progress.Line 支持渐变色。 diff --git a/antdv-demo b/antdv-demo index a7bf651da..8c9dee7ff 160000 --- a/antdv-demo +++ b/antdv-demo @@ -1 +1 @@ -Subproject commit a7bf651dafd694e8390c57e86eff2a2592000e86 +Subproject commit 8c9dee7ff6a3a18f335fba08073f14178fffb8b0 diff --git a/components/n-form/Form.jsx b/components/form-model/Form.jsx similarity index 94% rename from components/n-form/Form.jsx rename to components/form-model/Form.jsx index 2e2c15edc..e87be7cd3 100755 --- a/components/n-form/Form.jsx +++ b/components/form-model/Form.jsx @@ -46,7 +46,7 @@ export const ValidationRule = { }; const Form = { - name: 'ANForm', + name: 'AFormModel', props: initDefaultProps(FormProps, { layout: 'horizontal', hideRequiredMark: false, @@ -58,7 +58,7 @@ const Form = { }, provide() { return { - FormContext: this, + FormModelContext: this, }; }, inject: { @@ -96,7 +96,7 @@ const Form = { }, resetFields() { if (!this.model) { - warning(false, 'NewForm', 'model is required for resetFields to work.'); + warning(false, 'FormModel', 'model is required for resetFields to work.'); return; } this.fields.forEach(field => { @@ -115,7 +115,7 @@ const Form = { }, validate(callback) { if (!this.model) { - warning(false, 'NewForm', 'model is required for resetFields to work.'); + warning(false, 'FormModel', 'model is required for resetFields to work.'); return; } let promise; @@ -153,7 +153,7 @@ const Form = { props = [].concat(props); const fields = this.fields.filter(field => props.indexOf(field.prop) !== -1); if (!fields.length) { - warning(false, 'NewForm', 'please pass correct props!'); + warning(false, 'FormModel', 'please pass correct props!'); return; } fields.forEach(field => { diff --git a/components/n-form/FormItem.jsx b/components/form-model/FormItem.jsx similarity index 92% rename from components/n-form/FormItem.jsx rename to components/form-model/FormItem.jsx index fd293def6..d8afe3d77 100644 --- a/components/n-form/FormItem.jsx +++ b/components/form-model/FormItem.jsx @@ -62,7 +62,7 @@ export const FormItemProps = { }; export default { - name: 'ANFormItem', + name: 'AFormModelItem', __ANT_NEW_FORM_ITEM: true, mixins: [BaseMixin], props: initDefaultProps(FormItemProps, { @@ -71,12 +71,12 @@ export default { }), provide() { return { - NewFormItemContext: this, + FormModelItemContext: this, }; }, inject: { configProvider: { default: () => ConfigConsumerProps }, - FormContext: { default: () => ({}) }, + FormModelContext: { default: () => ({}) }, }, data() { return { @@ -89,7 +89,7 @@ export default { computed: { fieldValue() { - const model = this.FormContext.model; + const model = this.FormModelContext.model; if (!model || !this.prop) { return; } @@ -121,13 +121,13 @@ export default { }, mounted() { if (this.prop) { - const { addField } = this.FormContext; + const { addField } = this.FormModelContext; addField && addField(this); this.initialValue = cloneDeep(this.fieldValue); } }, beforeDestroy() { - const { removeField } = this.FormContext; + const { removeField } = this.FormModelContext; removeField && removeField(this); }, methods: { @@ -153,13 +153,13 @@ export default { this.validateState = errors ? 'error' : 'success'; this.validateMessage = errors ? errors[0].message : ''; callback(this.validateMessage, invalidFields); - this.FormContext && - this.FormContext.$emit && - this.FormContext.$emit('validate', this.prop, !errors, this.validateMessage || null); + this.FormModelContext && + this.FormModelContext.$emit && + this.FormModelContext.$emit('validate', this.prop, !errors, this.validateMessage || null); }); }, getRules() { - let formRules = this.FormContext.rules; + let formRules = this.FormModelContext.rules; const selfRules = this.rules; const requiredRule = this.required !== undefined ? { required: !!this.required, trigger: 'change' } : []; @@ -198,7 +198,7 @@ export default { resetField() { this.validateState = ''; this.validateMessage = ''; - let model = this.FormContext.model || {}; + let model = this.FormModelContext.model || {}; let value = this.fieldValue; let path = this.prop; if (path.indexOf(':') !== -1) { diff --git a/components/n-form/__tests__/__snapshots__/demo.test.js.snap b/components/form-model/__tests__/__snapshots__/demo.test.js.snap similarity index 79% rename from components/n-form/__tests__/__snapshots__/demo.test.js.snap rename to components/form-model/__tests__/__snapshots__/demo.test.js.snap index 94c017595..82cbde718 100644 --- a/components/n-form/__tests__/__snapshots__/demo.test.js.snap +++ b/components/form-model/__tests__/__snapshots__/demo.test.js.snap @@ -1,18 +1,18 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`renders ./antdv-demo/docs/n-form/demo/basic.md correctly 1`] = ` +exports[`renders ./antdv-demo/docs/form-model/demo/basic.md correctly 1`] = `