mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
Merge pull request #8842 from 2betop/fix-date-defaultValue
fix: 修复inputDate 配置 valueFormat + 表达式初始值时值不匹配 valueFormat Close: #8652
This commit is contained in:
commit
af68cce8d3
@ -522,6 +522,27 @@ test('Renderer:inputDate disabledDate', async () => {
|
|||||||
expect(tuesdayCell).not.toHaveClass('rdtDisabled');
|
expect(tuesdayCell).not.toHaveClass('rdtDisabled');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Renderer:inputDate defaultValue with formula', async () => {
|
||||||
|
const {container} = await setup([
|
||||||
|
{
|
||||||
|
type: 'input-date',
|
||||||
|
name: 'date',
|
||||||
|
label: '日期',
|
||||||
|
valueFormat: 'YYYY-MM-DD',
|
||||||
|
value: '${ DATE("2021-12-06 08:20:00") }'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
await wait(300);
|
||||||
|
const input = container.querySelector(
|
||||||
|
'.cxd-DatePicker-input'
|
||||||
|
)! as HTMLInputElement;
|
||||||
|
|
||||||
|
expect(input).toBeInTheDocument();
|
||||||
|
expect(input.value).toBe('2021-12-06');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
test('Renderer:inputDate setValue actions with special words', async () => {
|
test('Renderer:inputDate setValue actions with special words', async () => {
|
||||||
const {container, submitBtn, onSubmit, getByText} = await setup([
|
const {container, submitBtn, onSubmit, getByText} = await setup([
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,8 @@ import {
|
|||||||
FormControlProps,
|
FormControlProps,
|
||||||
FormBaseControl,
|
FormBaseControl,
|
||||||
resolveEventData,
|
resolveEventData,
|
||||||
str2function
|
str2function,
|
||||||
|
normalizeDate
|
||||||
} from 'amis-core';
|
} from 'amis-core';
|
||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
import {filterDate, isPureVariable, resolveVariableAndFilter} from 'amis-core';
|
import {filterDate, isPureVariable, resolveVariableAndFilter} from 'amis-core';
|
||||||
@ -404,7 +405,8 @@ export default class DateControl extends React.PureComponent<
|
|||||||
data,
|
data,
|
||||||
format,
|
format,
|
||||||
valueFormat,
|
valueFormat,
|
||||||
utc
|
utc,
|
||||||
|
changeMotivation
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
if (defaultValue && value === defaultValue) {
|
if (defaultValue && value === defaultValue) {
|
||||||
@ -412,6 +414,11 @@ export default class DateControl extends React.PureComponent<
|
|||||||
setPrinstineValue(
|
setPrinstineValue(
|
||||||
(utc ? moment.utc(date) : date).format(valueFormat || format)
|
(utc ? moment.utc(date) : date).format(valueFormat || format)
|
||||||
);
|
);
|
||||||
|
} else if (changeMotivation === 'formulaChanged' && defaultValue && value) {
|
||||||
|
const date = normalizeDate(value, valueFormat || format);
|
||||||
|
if (date && date.format(valueFormat || format) !== value) {
|
||||||
|
setPrinstineValue(date.format(valueFormat || format));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let schedulesData = props.schedules;
|
let schedulesData = props.schedules;
|
||||||
|
@ -179,6 +179,7 @@ export default class DateRangeControl extends React.Component<DateRangeProps> {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// todo 支持值格式的自动纠正
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps: DateRangeProps) {
|
componentDidUpdate(prevProps: DateRangeProps) {
|
||||||
|
Loading…
Reference in New Issue
Block a user