Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 75ccb58

Browse files
committed
Ensuring isReadOnlyValue checks only actual HTML inputs. Fixes #575
1 parent 55bf6a1 commit 75ccb58

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/components/control-component.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ function createControlClass(customControlPropsMap = {}, s = defaultStrategy) {
122122
...customControlPropsMap,
123123
};
124124

125-
function isReadOnlyValue(controlProps) {
126-
return ~['radio', 'checkbox'].indexOf(controlProps.type);
127-
}
128-
129125
const emptyControlProps = {};
130126

131127
class Control extends Component {
@@ -144,7 +140,6 @@ function createControlClass(customControlPropsMap = {}, s = defaultStrategy) {
144140
this.handleLoad = this.handleLoad.bind(this);
145141
this.getMappedProps = this.getMappedProps.bind(this);
146142
this.attachNode = this.attachNode.bind(this);
147-
this.readOnlyValue = isReadOnlyValue(props.controlProps);
148143

149144
this.willValidate = false;
150145

@@ -226,7 +221,7 @@ function createControlClass(customControlPropsMap = {}, s = defaultStrategy) {
226221
modelValue,
227222
changeAction,
228223
} = this.props;
229-
const value = this.readOnlyValue
224+
const value = this.isReadOnlyValue()
230225
? getReadOnlyValue(this.props)
231226
: event;
232227

@@ -351,11 +346,17 @@ function createControlClass(customControlPropsMap = {}, s = defaultStrategy) {
351346
}
352347

353348
setViewValue(viewValue) {
354-
if (!isReadOnlyValue(this.props.controlProps)) {
349+
if (!this.isReadOnlyValue()) {
355350
this.setState({ viewValue: this.parse(viewValue) });
356351
}
357352
}
358353

354+
isReadOnlyValue() {
355+
const { component, controlProps } = this.props;
356+
357+
return component === 'input' && ~['radio', 'checkbox'].indexOf(controlProps.type);
358+
}
359+
359360
handleIntents() {
360361
const {
361362
model,
@@ -375,12 +376,11 @@ function createControlClass(customControlPropsMap = {}, s = defaultStrategy) {
375376
case actionTypes.FOCUS: {
376377
if (isNative) return;
377378

378-
const readOnlyValue = isReadOnlyValue(controlProps);
379379
const focused = fieldValue.focus;
380380

381381
if ((focused && this.node.focus)
382382
&& (
383-
!readOnlyValue
383+
!this.isReadOnlyValue()
384384
|| typeof intent.value === 'undefined'
385385
|| intent.value === controlProps.value
386386
)) {
@@ -521,7 +521,7 @@ function createControlClass(customControlPropsMap = {}, s = defaultStrategy) {
521521
: event;
522522
}
523523

524-
if (isReadOnlyValue(controlProps)) {
524+
if (this.isReadOnlyValue()) {
525525
return compose(
526526
dispatchBatchActions,
527527
persistEventWithCallback(controlEventHandler || identity)

0 commit comments

Comments
 (0)