Skip to content

Set mask to TimePicker's editor on clear - 9.1.x #8237

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

Merged
merged 3 commits into from
Oct 6, 2020
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ng-template #dropdownInputTemplate>
<igx-input-group #group (mousedown)="mouseDown($event)">
<igx-input-group #group (mousedown)="mouseDown($event)" [suppressInputAutofocus]="true">
<label igxLabel>Time</label>
<igx-prefix (click)="openDialog(group.element.nativeElement)">
<igx-icon>access_time</igx-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,6 @@ describe('IgxTimePicker', () => {
fixture.componentInstance.format = 'hh tt';
fixture.componentInstance.customDate = new Date(2018, 10, 27, 17, 45, 0, 0);
fixture.detectChanges();

const clearTime = dom.queryAll(By.css('.igx-icon'))[1];

UIInteractions.simulateClickAndSelectEvent(clearTime);
Expand All @@ -1818,6 +1817,21 @@ describe('IgxTimePicker', () => {
expect(input.nativeElement.value).toBe('-- AM');
}));

it('should allow editing of input after clear', fakeAsync(() => {
fixture.componentInstance.format = 'hh tt';
fixture.componentInstance.customDate = new Date(2018, 10, 27, 17, 45, 0, 0);
fixture.detectChanges();
spyOn(fixture.componentInstance.timePicker, 'onInput');

const clearTime = dom.queryAll(By.css('.igx-icon'))[1];
UIInteractions.simulateClickAndSelectEvent(clearTime);
fixture.detectChanges();
const _input = fixture.debugElement.query(By.css('input'));
UIInteractions.simulateTyping('12 AM', _input);
expect(fixture.componentInstance.timePicker.onInput).not.toThrow();
expect(_input.nativeElement.value).toEqual('12 AM');
}));

it('Should navigate dropdown lists correctly when format contains only hours.', fakeAsync(() => {
fixture.componentInstance.format = 'hh tt';
fixture.componentInstance.customDate = new Date(2018, 10, 27, 17, 45, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { ITimePickerResourceStrings } from '../core/i18n/time-picker-resources';
import { CurrentResourceStrings } from '../core/i18n/resources';
import { KEYS, CancelableBrowserEventArgs, IBaseEventArgs } from '../core/utils';
import { InteractionMode } from '../core/enums';
import { IgxTextSelectionModule} from '../directives/text-selection/text-selection.directive';
import { IgxTextSelectionModule } from '../directives/text-selection/text-selection.directive';

let NEXT_ID = 0;
const ITEMS_COUNT = 7;
Expand Down Expand Up @@ -1894,9 +1894,12 @@ export class IgxTimePickerComponent implements
this.isNotEmpty = false;

const oldVal = new Date(this.value);

this.displayValue = '';
this.value.setHours(0, 0);
this.displayValue = this.parseMask(false);
requestAnimationFrame(() => {
this._setCursorPosition(0);
});
// TODO: refactoring - this.value should be null #6585
this.value?.setHours(0, 0, 0);

if (oldVal.getTime() !== this.value.getTime()) {
const args: IgxTimePickerValueChangedEventArgs = {
Expand All @@ -1914,35 +1917,35 @@ export class IgxTimePickerComponent implements
* @hidden
*/
public onInput(event): void {
const val = event.target.value;
const inputMask: string = event.target.value;
const oldVal = new Date(this.value);

this.isNotEmpty = val !== this.parseMask(false);
this.isNotEmpty = inputMask !== this.parseMask(false);

// handle cases where all empty positions (promts) are filled and we want to update
// timepicker own value property if it is a valid Date
if (val.indexOf(this.promptChar) === -1) {
if (this._isEntryValid(val)) {
const newVal = this._convertMinMaxValue(val);
if (inputMask.indexOf(this.promptChar) === -1) {
if (this._isEntryValid(inputMask)) {
const newVal = this._convertMinMaxValue(inputMask);
if (oldVal.getTime() !== newVal.getTime()) {
this.value = newVal;
}
} else {
const args: IgxTimePickerValidationFailedEventArgs = {
timePicker: this,
currentValue: val,
currentValue: new Date(inputMask),
setThroughUI: false
};
this.onValidationFailed.emit(args);
}
// handle cases where the user deletes the display value (when pressing backspace or delete)
} else if (!this.value || !val || val === this.parseMask(false)) {
} else if (!this.value || inputMask.length === 0 || !this.isNotEmpty) {
this.isNotEmpty = false;

this.value.setHours(0, 0);
this.displayValue = val;

if (oldVal.getTime() !== this.value.getTime()) {
// TODO: refactoring - this.value should be null #6585
this.value?.setHours(0, 0, 0);
this.displayValue = inputMask;
if (oldVal.getTime() !== this.value?.getTime()) {
// TODO: Do not emit event when the editor is empty #6482
const args: IgxTimePickerValueChangedEventArgs = {
oldValue: oldVal,
newValue: this.value
Expand All @@ -1969,7 +1972,7 @@ export class IgxTimePickerComponent implements
this.isNotEmpty = value !== '';
this.displayValue = value;

if (value && value !== this.parseMask()) {
if (value && (value !== this.parseMask() || value !== this.parseMask(false))) {
if (this._isEntryValid(value)) {
const newVal = this._convertMinMaxValue(value);
if (!this.value || this.value.getTime() !== newVal.getTime()) {
Expand Down