Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复inputDate 配置 valueFormat + 表达式初始值时值不匹配 valueFormat Close: #8652 #8842

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/amis/__tests__/renderers/Form/inputDate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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([
{
Expand Down
11 changes: 9 additions & 2 deletions packages/amis/src/renderers/Form/InputDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -404,14 +405,20 @@ export default class DateControl extends React.PureComponent<
data,
format,
valueFormat,
utc
utc,
changeMotivation
} = props;

if (defaultValue && value === defaultValue) {
const date = filterDate(defaultValue, data, valueFormat || format);
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;
Expand Down
1 change: 1 addition & 0 deletions packages/amis/src/renderers/Form/InputDateRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export default class DateRangeControl extends React.Component<DateRangeProps> {
)
);
}
// todo 支持值格式的自动纠正
}

componentDidUpdate(prevProps: DateRangeProps) {
Expand Down
Loading