@uform/core
Advanced tools
Comparing version 0.1.0-alpha.21 to 0.1.0-beta.2
@@ -31,2 +31,3 @@ "use strict"; | ||
this.valid = true; | ||
this.removed = false; | ||
this.invalid = false; | ||
@@ -47,15 +48,27 @@ this.visible = true; | ||
_proto.initialize = function initialize(options) { | ||
var editable = this.getEditableFromProps(options.props); | ||
var rules = this.getRulesFromProps(options.props); | ||
this.value = !(0, _utils.isEmpty)(options.value) ? (0, _utils.clone)(options.value) : this.value; | ||
this.initialValue = !(0, _utils.isEmpty)(options.initialValue) ? options.initialValue : this.initialValue; | ||
this.initialValue = !(0, _utils.isEmpty)(options.initialValue) ? options.initialValue : !(0, _utils.isEmpty)(this.initialValue) ? this.initialValue : this.getInitialValueFromProps(options.props); | ||
this.name = !(0, _utils.isEmpty)(options.name) ? options.name : this.name || ''; | ||
this.namePath = (0, _utils.resolveFieldPath)(this.name); | ||
var editable = this.getEditableFromProps(options.props); | ||
this.editable = !(0, _utils.isEmpty)(editable) ? editable : this.editable; | ||
this.path = (0, _utils.resolveFieldPath)(!(0, _utils.isEmpty)(options.path) ? options.path : this.path || []); | ||
var rules = this.getRulesFromProps(options.props); | ||
this.rules = !(0, _utils.isEmpty)(rules) ? rules : this.rules; | ||
this.required = (0, _utils.hasRequired)(this.rules); | ||
this.props = !(0, _utils.isEmpty)(options.props) ? !(0, _utils.isEmpty)(this.props) ? (0, _extends2.default)({}, this.props, (0, _utils.clone)(options.props)) : (0, _utils.clone)(options.props) : this.props; | ||
this.visible = true; | ||
if (this.removed) { | ||
this.removed = false; | ||
this.visible = true; | ||
} | ||
if (!this.initialized) { | ||
if ((0, _utils.isEmpty)(this.value) && !(0, _utils.isEmpty)(this.initialValue)) { | ||
this.value = (0, _utils.clone)(this.initialValue); | ||
this.context.setIn(this.name, this.value); | ||
this.context.setInitialValueIn(this.name, this.initialValue); | ||
} | ||
} | ||
if ((0, _utils.isFn)(options.onChange)) { | ||
@@ -66,2 +79,10 @@ this.onChange(options.onChange); | ||
_proto.getInitialValueFromProps = function getInitialValueFromProps(props) { | ||
if (props) { | ||
if (!(0, _utils.isEmpty)(props['default'])) { | ||
return props['default']; | ||
} | ||
} | ||
}; | ||
_proto.getEditableFromProps = function getEditableFromProps(props) { | ||
@@ -171,2 +192,3 @@ if (props) { | ||
this.visible = false; | ||
this.removed = true; | ||
if (!this.context) return; | ||
@@ -173,0 +195,0 @@ this.context.deleteIn(this.name); |
{ | ||
"name": "@uform/core", | ||
"version": "0.1.0-alpha.21", | ||
"version": "0.1.0-beta.2", | ||
"license": "MIT", | ||
@@ -28,3 +28,3 @@ "main": "lib", | ||
}, | ||
"gitHead": "0b7ba2a852d91cd0507d8243c980b6e5b4dc5d32" | ||
"gitHead": "1c1dfd2fdf1d0bdbad3a69b311905a11f9673542" | ||
} |
@@ -27,2 +27,3 @@ import { | ||
this.valid = true | ||
this.removed = false | ||
this.invalid = false | ||
@@ -41,9 +42,12 @@ this.visible = true | ||
initialize(options) { | ||
const editable = this.getEditableFromProps(options.props) | ||
const rules = this.getRulesFromProps(options.props) | ||
this.value = !isEmpty(options.value) ? clone(options.value) : this.value | ||
this.initialValue = !isEmpty(options.initialValue) | ||
? options.initialValue | ||
: this.initialValue | ||
: !isEmpty(this.initialValue) | ||
? this.initialValue | ||
: this.getInitialValueFromProps(options.props) | ||
this.name = !isEmpty(options.name) ? options.name : this.name || '' | ||
this.namePath = resolveFieldPath(this.name) | ||
const editable = this.getEditableFromProps(options.props) | ||
this.editable = !isEmpty(editable) ? editable : this.editable | ||
@@ -53,3 +57,2 @@ this.path = resolveFieldPath( | ||
) | ||
const rules = this.getRulesFromProps(options.props) | ||
this.rules = !isEmpty(rules) ? rules : this.rules | ||
@@ -62,3 +65,13 @@ this.required = hasRequired(this.rules) | ||
: this.props | ||
this.visible = true | ||
if (this.removed) { | ||
this.removed = false | ||
this.visible = true | ||
} | ||
if (!this.initialized) { | ||
if (isEmpty(this.value) && !isEmpty(this.initialValue)) { | ||
this.value = clone(this.initialValue) | ||
this.context.setIn(this.name, this.value) | ||
this.context.setInitialValueIn(this.name, this.initialValue) | ||
} | ||
} | ||
if (isFn(options.onChange)) { | ||
@@ -69,2 +82,10 @@ this.onChange(options.onChange) | ||
getInitialValueFromProps(props) { | ||
if (props) { | ||
if (!isEmpty(props['default'])) { | ||
return props['default'] | ||
} | ||
} | ||
} | ||
getEditableFromProps(props) { | ||
@@ -163,2 +184,3 @@ if (props) { | ||
this.visible = false | ||
this.removed = true | ||
if (!this.context) return | ||
@@ -165,0 +187,0 @@ this.context.deleteIn(this.name) |
71230
2179