fix: can't set default value when turn on the form field required (#1887)

* fix: can't set default value when turn on the form field required

* fix: can't set default value when turn on the association select field required
This commit is contained in:
black 2023-05-22 17:22:01 +08:00 committed by GitHub
parent 110b00bc01
commit db349ccb68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -160,6 +160,8 @@ AssociationSelect.Designer = function Designer() {
readOnlyMode = 'read-pretty'; readOnlyMode = 'read-pretty';
} }
const fieldSchemaWithoutRequired = _.omit(fieldSchema,'required')
return ( return (
<GeneralSchemaDesigner> <GeneralSchemaDesigner>
<GeneralSchemaItems /> <GeneralSchemaItems />
@ -299,10 +301,10 @@ AssociationSelect.Designer = function Designer() {
title: t('Set default value'), title: t('Set default value'),
properties: { properties: {
default: { default: {
...(fieldSchema || {}), ...(fieldSchemaWithoutRequired || {}),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component-props': { 'x-component-props': {
...fieldSchema['x-component-props'], ...fieldSchemaWithoutRequired['x-component-props'],
component: collectionField?.target ? 'AssociationSelect' : undefined, component: collectionField?.target ? 'AssociationSelect' : undefined,
service: { service: {
resource: collectionField?.target, resource: collectionField?.target,
@ -812,7 +814,7 @@ AssociationSelect.FilterDesigner = function FilterDesigner() {
title: t('Set default value'), title: t('Set default value'),
properties: { properties: {
default: { default: {
...collectionField?.uiSchema, ..._.omit(collectionField?.uiSchema, 'required'),
name: 'default', name: 'default',
title: t('Default value'), title: t('Default value'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',

View File

@ -172,6 +172,8 @@ FormItem.Designer = function Designer() {
}; };
}); });
const fieldSchemaWithoutRequired = _.omit(fieldSchema,'required')
return ( return (
<GeneralSchemaDesigner> <GeneralSchemaDesigner>
<GeneralSchemaItems /> <GeneralSchemaItems />
@ -352,7 +354,7 @@ FormItem.Designer = function Designer() {
properties: { properties: {
default: isInvariable(interfaceConfig) default: isInvariable(interfaceConfig)
? { ? {
...(fieldSchema || {}), ...(fieldSchemaWithoutRequired || {}),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component-props': { 'x-component-props': {
...fieldSchema['x-component-props'], ...fieldSchema['x-component-props'],
@ -375,7 +377,7 @@ FormItem.Designer = function Designer() {
'x-disabled': false, 'x-disabled': false,
} }
: { : {
...(fieldSchema || {}), ...(fieldSchemaWithoutRequired || {}),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'VariableInput', 'x-component': 'VariableInput',
'x-component-props': { 'x-component-props': {
@ -384,7 +386,7 @@ FormItem.Designer = function Designer() {
schema: collectionField?.uiSchema, schema: collectionField?.uiSchema,
className: defaultInputStyle, className: defaultInputStyle,
renderSchemaComponent: function Com(props) { renderSchemaComponent: function Com(props) {
const s = _.cloneDeep(fieldSchema) || ({} as Schema); const s = _.cloneDeep(fieldSchemaWithoutRequired) || ({} as Schema);
s.title = ''; s.title = '';
s['x-read-pretty'] = false; s['x-read-pretty'] = false;
s['x-disabled'] = false; s['x-disabled'] = false;