fix(defaultValue): should not use defaultValue in filter blocks (#3472)
This commit is contained in:
parent
89bf75871f
commit
e7a28035c2
@ -1,13 +1,14 @@
|
||||
import React from 'react';
|
||||
import { DatePickerProvider } from '../schema-component';
|
||||
import { DefaultValueProvider } from '../schema-settings';
|
||||
import { FormBlockProvider } from './FormBlockProvider';
|
||||
|
||||
export const FilterFormBlockProvider = (props) => {
|
||||
const { collection, resource } = props;
|
||||
|
||||
return (
|
||||
<DatePickerProvider value={{ utc: false }}>
|
||||
<FormBlockProvider name="filter-form" {...props}></FormBlockProvider>
|
||||
<DefaultValueProvider isAllowToSetDefaultValue={() => false}>
|
||||
<FormBlockProvider name="filter-form" {...props}></FormBlockProvider>
|
||||
</DefaultValueProvider>
|
||||
</DatePickerProvider>
|
||||
);
|
||||
};
|
||||
|
@ -5,6 +5,7 @@ import { concat } from 'lodash';
|
||||
import React, { useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useActionContext, useCompile, useComponent, useFormBlockContext, useRecord } from '..';
|
||||
import useIsAllowToSetDefaultValue from '../schema-settings/hooks/useIsAllowToSetDefaultValue';
|
||||
import { CollectionFieldProvider } from './CollectionFieldProvider';
|
||||
import { useCollectionField } from './hooks';
|
||||
|
||||
@ -19,6 +20,7 @@ const InternalField: React.FC = (props: Props) => {
|
||||
const field = useField<Field>();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const { uiSchema, defaultValue } = useCollectionField();
|
||||
const { isAllowToSetDefaultValue } = useIsAllowToSetDefaultValue();
|
||||
const Component = useComponent(component || uiSchema?.['x-component'] || 'Input');
|
||||
const compile = useCompile();
|
||||
const setFieldProps = (key, value) => {
|
||||
@ -46,7 +48,7 @@ const InternalField: React.FC = (props: Props) => {
|
||||
setFieldProps('title', uiSchema.title);
|
||||
setFieldProps('description', uiSchema.description);
|
||||
if (ctx?.form) {
|
||||
const defaultVal = fieldSchema.default || defaultValue;
|
||||
const defaultVal = isAllowToSetDefaultValue() ? fieldSchema.default || defaultValue : undefined;
|
||||
defaultVal !== null && defaultVal !== undefined && setFieldProps('initialValue', defaultVal);
|
||||
}
|
||||
if (!field.validator && (uiSchema['x-validator'] || fieldSchema['x-validator'])) {
|
||||
|
Loading…
Reference in New Issue
Block a user