availity-reactstrap-validation
Advanced tools
Comparing version 1.2.8 to 1.3.0
@@ -49,3 +49,3 @@ 'use strict'; | ||
AvBaseInput.prototype.componentWillMount = function componentWillMount() { | ||
this.value = this.props.value || this.getDefaultValue().value; | ||
this.value = this.props.value || this.getDefaultValue(); | ||
this.setState({ value: this.value }); | ||
@@ -56,6 +56,18 @@ this.updateValidations(); | ||
AvBaseInput.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
if (nextProps.value !== this.props.value) { | ||
this.value = nextProps.value; | ||
this.setState({ value: nextProps.value }); | ||
if (nextProps.type === 'checkbox') { | ||
if (nextProps.checked !== this.props.checked) { | ||
if (nextProps.checked) { | ||
this.value = nextProps.trueValue; | ||
} else { | ||
this.value = nextProps.falseValue; | ||
} | ||
this.setState({ value: this.value }); | ||
} | ||
} else { | ||
if (nextProps.value !== this.props.value) { | ||
this.value = nextProps.value; | ||
this.setState({ value: nextProps.value }); | ||
} | ||
} | ||
if (!(0, _lodash4.default)(nextProps, this.props)) { | ||
@@ -102,11 +114,18 @@ this.updateValidations(nextProps); | ||
AvBaseInput.prototype.getDefaultValue = function getDefaultValue() { | ||
var key = 'defaultValue'; | ||
var defaultValue = ''; | ||
if (this.props.type === 'checkbox') { | ||
key = 'defaultChecked'; | ||
if (!(0, _lodash2.default)(this.props.defaultChecked)) { | ||
return this.props.defaultChecked ? this.props.trueValue : this.props.falseValue; | ||
} | ||
defaultValue = this.props.falseValue; | ||
} | ||
var value = this.props[key] || this.context.FormCtrl.getDefaultValue(this.props.name) || ''; | ||
var value = this.props.defaultValue || this.context.FormCtrl.getDefaultValue(this.props.name); | ||
return { key: key, value: value }; | ||
if (this.props.type === 'checkbox' && value !== this.props.trueValue) { | ||
value = defaultValue; | ||
} | ||
return (0, _lodash2.default)(value) ? defaultValue : value; | ||
}; | ||
@@ -116,3 +135,3 @@ | ||
if (this.props.type === 'checkbox') { | ||
return event.target.checked; | ||
return event.target.checked ? this.props.trueValue : this.props.falseValue; | ||
} | ||
@@ -146,2 +165,6 @@ return event && event.target && !(0, _lodash2.default)(event.target.value) ? event.target.value : event; | ||
if (this.props.type === 'checkbox') { | ||
newProps.checked = this.value === this.props.trueValue; | ||
} | ||
if (state) { | ||
@@ -159,3 +182,3 @@ newProps.state = state; | ||
AvBaseInput.prototype.reset = function reset() { | ||
this.value = this.getDefaultValue().value; | ||
this.value = this.getDefaultValue(); | ||
this.context.FormCtrl.setDirty(this.props.name, false); | ||
@@ -214,2 +237,7 @@ this.context.FormCtrl.setTouched(this.props.name, false); | ||
value: _react.PropTypes.any, | ||
defaultValue: _react.PropTypes.any, | ||
trueValue: _react.PropTypes.any, | ||
falseValue: _react.PropTypes.any, | ||
checked: _react.PropTypes.bool, | ||
defaultChecked: _react.PropTypes.bool, | ||
state: _react.PropTypes.bool, | ||
@@ -229,4 +257,6 @@ type: _react.PropTypes.string, | ||
validationEvent: '', | ||
validate: {} | ||
validate: {}, | ||
trueValue: true, | ||
falseValue: false | ||
}; | ||
exports.default = AvBaseInput; |
@@ -108,3 +108,3 @@ 'use strict'; | ||
_extends({ disabled: disabled, row: row }, groupAttrs), | ||
_react2.default.createElement( | ||
label && _react2.default.createElement( | ||
_reactstrap.Label, | ||
@@ -111,0 +111,0 @@ _extends({ |
@@ -46,6 +46,8 @@ 'use strict'; | ||
var omit4 = _props.state; | ||
var omit5 = _props.trueValue; | ||
var omit6 = _props.falseValue; | ||
var className = _props.className; | ||
var Tag = _props.tag; | ||
var attributes = _objectWithoutProperties(_props, ['errorMessage', 'validate', 'validationEvent', 'state', 'className', 'tag']); | ||
var attributes = _objectWithoutProperties(_props, ['errorMessage', 'validate', 'validationEvent', 'state', 'trueValue', 'falseValue', 'className', 'tag']); | ||
@@ -52,0 +54,0 @@ var classes = (0, _classnames2.default)(className, this.context.FormCtrl.isTouched[this.props.name] ? 'av-touched' : 'av-untouched', this.context.FormCtrl.isDirty[this.props.name] ? 'av-dirty' : 'av-pristine', this.context.FormCtrl.isBad[this.props.name] ? 'av-bad-input' : null, this.context.FormCtrl.hasError[this.props.name] ? 'av-invalid' : 'av-valid'); |
{ | ||
"name": "availity-reactstrap-validation", | ||
"version": "1.2.8", | ||
"version": "1.3.0", | ||
"author": "Evan Sharp <evan.sharp@availity.com>", | ||
@@ -5,0 +5,0 @@ "description": "Form validation helpers for reactstrap", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
6441597
35628