From cd45ab33bc4af2cee07f920535918fb97759f6c9 Mon Sep 17 00:00:00 2001 From: Jiaqi Liu Date: Wed, 6 Mar 2019 13:01:43 +0800 Subject: [PATCH] fix(Field): fix bug when change the name of Field --- lib/Field.js | 16 +++++++++------- src/Field.js | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/Field.js b/lib/Field.js index 23e04e3..185d496 100644 --- a/lib/Field.js +++ b/lib/Field.js @@ -128,13 +128,15 @@ var Field = (_temp = _class = function (_Component) { }, { key: 'componentDidUpdate', value: function componentDidUpdate(prevProps) { - if (this.$formContext.$$register && prevProps.name !== this.$name) { - this.$name = this.props.name; - - if (this.$name) { - this.$formContext.$$register(this.$name, this.$handler, prevProps.name); - } else { - this.$formContext.$$unregister(prevProps.$name, this.$handler); + if (this.props.name !== prevProps.name) { + this.$name = this.$handler.$name = this.props.name; + + if (this.$formContext.$$register) { + if (this.$name) { + this.$formContext.$$register(this.$name, this.$handler, prevProps.name); + } else { + this.$formContext.$$unregister(prevProps.$name, this.$handler); + } } } } diff --git a/src/Field.js b/src/Field.js index 1f12bef..2d2aa05 100644 --- a/src/Field.js +++ b/src/Field.js @@ -126,13 +126,15 @@ class Field extends Component { } componentDidUpdate(prevProps) { - if (this.$formContext.$$register && prevProps.name !== this.$name) { - this.$name = this.props.name; - - if (this.$name) { - this.$formContext.$$register(this.$name, this.$handler, prevProps.name); - } else { - this.$formContext.$$unregister(prevProps.$name, this.$handler); + if (this.props.name !== prevProps.name) { + this.$name = this.$handler.$name = this.props.name; + + if (this.$formContext.$$register) { + if (this.$name) { + this.$formContext.$$register(this.$name, this.$handler, prevProps.name); + } else { + this.$formContext.$$unregister(prevProps.$name, this.$handler); + } } } }