mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 10:38:16 +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');
|
||||
});
|
||||
|
||||
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 () => {
|
||||
const {container, submitBtn, onSubmit, getByText} = await setup([
|
||||
{
|
||||
|
@ -4,7 +4,8 @@ import {
|
||||
FormControlProps,
|
||||
FormBaseControl,
|
||||
resolveEventData,
|
||||
str2function
|
||||
str2function,
|
||||
normalizeDate
|
||||
} from 'amis-core';
|
||||
import cx from 'classnames';
|
||||
import {filterDate, isPureVariable, resolveVariableAndFilter} from 'amis-core';
|
||||
@ -404,7 +405,8 @@ export default class DateControl extends React.PureComponent<
|
||||
data,
|
||||
format,
|
||||
valueFormat,
|
||||
utc
|
||||
utc,
|
||||
changeMotivation
|
||||
} = props;
|
||||
|
||||
if (defaultValue && value === defaultValue) {
|
||||
@ -412,6 +414,11 @@ export default class DateControl extends React.PureComponent<
|
||||
setPrinstineValue(
|
||||
(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;
|
||||
|
@ -179,6 +179,7 @@ export default class DateRangeControl extends React.Component<DateRangeProps> {
|
||||
)
|
||||
);
|
||||
}
|
||||
// todo 支持值格式的自动纠正
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: DateRangeProps) {
|
||||
|
Loading…
Reference in New Issue
Block a user