Skip to content

Commit

Permalink
fix(editor): 勾选框组件值格式配置支持不同类型选择
Browse files Browse the repository at this point in the history
  • Loading branch information
yangwei9012 committed Jan 16, 2024
1 parent 8aecaff commit 290dbde
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 191 deletions.
1 change: 1 addition & 0 deletions packages/amis-editor/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './tpl/index';
export * from './plugin';

import './renderer/OptionControl';
import './renderer/ValueFormatControl';
import './renderer/NavSourceControl';
import './renderer/KeyValueMapControl';
import './renderer/NavBadgeControl';
Expand Down
25 changes: 15 additions & 10 deletions packages/amis-editor/src/plugin/Form/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
setSchemaTpl,
getSchemaTpl,
valuePipeOut,
undefinedPipeOut,
EditorNodeType,
EditorManager
} from 'amis-editor-core';
Expand Down Expand Up @@ -138,44 +139,48 @@ export class CheckboxControlPlugin extends BasePlugin {
form: {
body: [
{
type: 'input-text',
label: '勾选值',
type: 'ae-valueFormat',
name: 'trueValue',
label: '勾选值',
pipeIn: defaultValue(true),
pipeOut: valuePipeOut,
pipeOut: undefinedPipeOut,
onChange: (
value: any,
oldValue: any,
model: any,
form: any
) => {
const defaultValue = form?.data?.value;
const {value: defaultValue, trueValue} =
form?.data || {};
if (isPureVariable(defaultValue)) {
return;
}
if (oldValue === defaultValue) {
if (trueValue === defaultValue && trueValue !== value) {
form.setValues({value});
}
}
},
{
type: 'input-text',
label: '未勾选值',
type: 'ae-valueFormat',
name: 'falseValue',
label: '未勾选值',
pipeIn: defaultValue(false),
pipeOut: valuePipeOut,
pipeOut: undefinedPipeOut,
onChange: (
value: any,
oldValue: any,
model: any,
form: any
) => {
const {value: defaultValue, trueValue} =
const {value: defaultValue, falseValue} =
form?.data || {};
if (isPureVariable(defaultValue)) {
return;
}
if (trueValue !== defaultValue) {
if (
falseValue === defaultValue &&
falseValue !== value
) {
form.setValues({value});
}
}
Expand Down

0 comments on commit 290dbde

Please sign in to comment.