mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 10:41:13 +08:00
fix(datetime): empty string is treated as no value (#26131)
resolves #26116
This commit is contained in:
@ -19,7 +19,7 @@ export class ValueAccessor implements ControlValueAccessor, AfterViewInit, OnDes
|
|||||||
|
|
||||||
writeValue(value: any): void {
|
writeValue(value: any): void {
|
||||||
/**
|
/**
|
||||||
* TODO for Ionic 6:
|
* TODO FW-2646
|
||||||
* Change `value == null ? '' : value;`
|
* Change `value == null ? '' : value;`
|
||||||
* to `value`. This was a fix for IE9, but IE9
|
* to `value`. This was a fix for IE9, but IE9
|
||||||
* is no longer supported; however, this change
|
* is no longer supported; however, this change
|
||||||
|
@ -160,7 +160,8 @@ export class DatetimeButton implements ComponentInterface {
|
|||||||
* to keep checking if the datetime value is `string` or `string[]`.
|
* to keep checking if the datetime value is `string` or `string[]`.
|
||||||
*/
|
*/
|
||||||
private getParsedDateValues = (value?: string[] | string | null): string[] => {
|
private getParsedDateValues = (value?: string[] | string | null): string[] => {
|
||||||
if (value === undefined || value === null) {
|
// TODO FW-2646 Remove value === ''
|
||||||
|
if (value === '' || value === undefined || value === null) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1154,8 +1154,11 @@ export class Datetime implements ComponentInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private processValue = (value?: string | string[] | null) => {
|
private processValue = (value?: string | string[] | null) => {
|
||||||
const hasValue = value !== null && value !== undefined;
|
/**
|
||||||
let valueToProcess = parseDate(value ?? getToday());
|
* TODO FW-2646 remove value !== ''
|
||||||
|
*/
|
||||||
|
const hasValue = value !== '' && value !== null && value !== undefined;
|
||||||
|
let valueToProcess = parseDate(hasValue ? value : getToday());
|
||||||
|
|
||||||
const { minParts, maxParts, multiple } = this;
|
const { minParts, maxParts, multiple } = this;
|
||||||
if (!multiple && Array.isArray(value)) {
|
if (!multiple && Array.isArray(value)) {
|
||||||
|
@ -50,3 +50,17 @@ test.describe('datetime: values', () => {
|
|||||||
await expect(items).toHaveText(['01', '02', '03']);
|
await expect(items).toHaveText(['01', '02', '03']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('setting value to empty string should treat it as having no date', async ({ page, skip }) => {
|
||||||
|
skip.rtl();
|
||||||
|
skip.mode('ios');
|
||||||
|
await page.setContent(`
|
||||||
|
<ion-datetime value="" locale="en-US"></ion-datetime>
|
||||||
|
`);
|
||||||
|
|
||||||
|
await page.waitForSelector('.datetime-ready');
|
||||||
|
|
||||||
|
// Should render current month with today outlined.
|
||||||
|
const calendarDayToday = page.locator('ion-datetime .calendar-day-today');
|
||||||
|
await expect(calendarDayToday).toBeVisible();
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user