react-redux-form
react-redux-form copied to clipboard
Checkbox in LocalForm updating twice (once with invalid value)
The Problem
The checkbox component in LocalForm triggers validator once with "on" and once with true.
Steps to Reproduce
Open https://codepen.io/anon/pen/XZpMwq , open console and trigger checkbox change.
Expected Behavior
Only true or false are given to validators.
I changed my get-value.js file to:
function getEventValue(event) {
...
if (target.type === 'checkbox') {
return target.checked;
}
...
}
...
function getCheckboxValue(value, props) {
var controlProps = props.controlProps;
if ((0, _isMulti2.default)(props.model)) {
return controlProps.value;
}
debugger;
return getValue(value)
}
So at least I get correct truthy values. But it is still triggering somewhere another change where it sets "on" as value. (props.controProps.modelValue by the way is always undefined)
Could it be tha in control-component-factory.js -> createEventHandler on handleUpdate
if (this.props.isToggle) {
return compose(
dispatchBatchActions,
persistEventWithCallback(controlEventHandler || identity)
)(event);
}
is doing something unexpected?
It might actually be a combination of things in control-props-map.js and control-component-factory with changeAction. 🔍
When I log [model].concat(args) in trackable (in track.js) I get following on one click of the checkbox

It's not just checkboxes updating necessary often. When I create a textfield and give it a parser and formatter my parser gets two times a string value and the last time the parsed value :( In control-component-factory -> componentWillReceiveProps it does:
value: function componentWillReceiveProps(_ref) {
var modelValue = _ref.modelValue;
if (modelValue !== this.props.modelValue) {
this.setViewValue(modelValue);
}
}
so viewValue actually receives the parsed value right? But in setViewValue it agains parses the modelValue.
value: function setViewValue(viewValue) {
if (!this.props.isToggle) {
if (this.props.formatter) {
var parsedValue = this.parse(viewValue);
this.setState({ viewValue: this.format(parsedValue) });
} else {
this.setState({ viewValue: this.parse(viewValue) });
}
}
}