diff --git a/src/renderers/Form/ChainedSelect.tsx b/src/renderers/Form/ChainedSelect.tsx index 2b9e7ea7d..530cde8da 100644 --- a/src/renderers/Form/ChainedSelect.tsx +++ b/src/renderers/Form/ChainedSelect.tsx @@ -84,11 +84,25 @@ export default class ChainedSelectControl extends React.Component< doAction(action: Action, data: object, throwErrors: boolean) { const {resetValue, onChange} = this.props; - if (action.actionType === 'clear') { + const actionType = action?.actionType as string; + + if (!!~['clear', 'reset'].indexOf(actionType)) { onChange(resetValue ?? ''); } } + array2value(arr: Array, isExtracted: boolean = false) { + const {delimiter, joinValues, extractValue} = this.props; + // 判断arr的项是否已抽取 + return isExtracted + ? (joinValues ? arr.join(delimiter || ',') : arr) + : (joinValues + ? arr.join(delimiter || ',') + : extractValue + ? arr.map(item => item.value || item) + : arr) + } + loadMore() { const { value, @@ -157,10 +171,12 @@ export default class ChainedSelectControl extends React.Component< arr.splice(idx + 1, value.length - idx - 1); arr.push(remoteValue); + const valueRes = this.array2value(arr, true); + const rendererEvent = await dispatchEvent( 'change', createObject(data, { - value: joinValues ? arr.join(delimiter || ',') : arr + value: valueRes }) ); @@ -168,7 +184,7 @@ export default class ChainedSelectControl extends React.Component< return; } - onChange(joinValues ? arr.join(delimiter || ',') : arr); + onChange(valueRes); } stack.push({ @@ -203,11 +219,7 @@ export default class ChainedSelectControl extends React.Component< arr.splice(index, arr.length - index); arr.push(joinValues ? currentValue.value : currentValue); - const valueRes = joinValues - ? arr.join(delimiter || ',') - : extractValue - ? arr.map(item => item.value || item) - : arr; + const valueRes = this.array2value(arr); const rendererEvent = await dispatchEvent( 'change', diff --git a/src/renderers/Form/Checkbox.tsx b/src/renderers/Form/Checkbox.tsx index dac23b34b..16a76e5f4 100644 --- a/src/renderers/Form/Checkbox.tsx +++ b/src/renderers/Form/Checkbox.tsx @@ -55,8 +55,10 @@ export default class CheckboxControl extends React.Component< doAction(action: Action, data: object, throwErrors: boolean) { const {resetValue, onChange} = this.props; - if (action.actionType === 'clear') { - onChange(resetValue ?? false); + const actionType = action?.actionType as string; + + if (!!~['clear', 'reset'].indexOf(actionType)) { + onChange(resetValue ?? ''); } } diff --git a/src/renderers/Form/InputTag.tsx b/src/renderers/Form/InputTag.tsx index 6bc93aec5..b9ad75a96 100644 --- a/src/renderers/Form/InputTag.tsx +++ b/src/renderers/Form/InputTag.tsx @@ -83,7 +83,9 @@ export default class TagControl extends React.PureComponent< doAction(action: Action, data: object, throwErrors: boolean) { const {resetValue, onChange} = this.props; - if (action.actionType === 'clear') { + const actionType = action?.actionType as string; + + if (!!~['clear', 'reset'].indexOf(actionType)) { onChange(resetValue ?? ''); } } diff --git a/src/renderers/Form/MatrixCheckboxes.tsx b/src/renderers/Form/MatrixCheckboxes.tsx index a7c3bba10..9e0a36ebb 100644 --- a/src/renderers/Form/MatrixCheckboxes.tsx +++ b/src/renderers/Form/MatrixCheckboxes.tsx @@ -149,7 +149,9 @@ export default class MatrixCheckbox extends React.Component< doAction(action: Action, data: object, throwErrors: boolean) { const {resetValue, onChange} = this.props; - if (action.actionType === 'clear') { + const actionType = action?.actionType as string; + + if (!!~['clear', 'reset'].indexOf(actionType)) { onChange(resetValue ?? ''); } } diff --git a/src/renderers/Form/NestedSelect.tsx b/src/renderers/Form/NestedSelect.tsx index a4246ebfb..59d450db0 100644 --- a/src/renderers/Form/NestedSelect.tsx +++ b/src/renderers/Form/NestedSelect.tsx @@ -121,7 +121,9 @@ export default class NestedSelectControl extends React.Component< doAction(action: Action, data: object, throwErrors: boolean) { const {resetValue, onChange} = this.props; - if (action.actionType === 'clear') { + const actionType = action?.actionType as string; + + if (!!~['clear', 'reset'].indexOf(actionType)) { onChange(resetValue ?? ''); } } diff --git a/src/renderers/Form/Options.tsx b/src/renderers/Form/Options.tsx index 7bd081286..b2666d54a 100644 --- a/src/renderers/Form/Options.tsx +++ b/src/renderers/Form/Options.tsx @@ -469,7 +469,9 @@ export function registerOptionsControl(config: OptionsConfig) { doAction(action: Action, data: object, throwErrors: boolean) { const {resetValue, onChange} = this.props; - if (action.actionType === 'clear') { + const actionType = action?.actionType as string; + + if (!!~['clear', 'reset'].indexOf(actionType)) { onChange(resetValue ?? ''); } } diff --git a/src/renderers/Form/Radios.tsx b/src/renderers/Form/Radios.tsx index f964973b4..1a383c25c 100644 --- a/src/renderers/Form/Radios.tsx +++ b/src/renderers/Form/Radios.tsx @@ -39,7 +39,9 @@ export default class RadiosControl extends React.Component { doAction(action: Action, data: object, throwErrors: boolean) { const {resetValue, onChange} = this.props; - if (action.actionType === 'clear') { + const actionType = action?.actionType as string; + + if (!!~['clear', 'reset'].indexOf(actionType)) { onChange(resetValue ?? ''); } } diff --git a/src/renderers/Form/Select.tsx b/src/renderers/Form/Select.tsx index 2648120ef..050995412 100644 --- a/src/renderers/Form/Select.tsx +++ b/src/renderers/Form/Select.tsx @@ -336,8 +336,10 @@ export default class SelectControl extends React.Component { } doAction(action: Action, data: object, throwErrors: boolean): any { - const {simpleValue, resetValue} = this.props; - if (action.actionType === 'clear') { + const {resetValue} = this.props; + const actionType = action?.actionType as string; + + if (!!~['clear', 'reset'].indexOf(actionType)) { this.changeValue(resetValue ?? ''); } }