focus on day list input on delete and add choice

This commit is contained in:
Tykayn 2022-03-03 11:29:11 +01:00 committed by tykayn
parent 8a22dd85eb
commit 0b1c909182
2 changed files with 9 additions and 9 deletions

View File

@ -29,7 +29,7 @@
<div class="delete-date">
<button
class="has-no-outline has-no-background has-text-primary has-text-left"
(click)="dateChoices.splice(id, 1)"
(click)="deleteChoiceField(id)"
>
<img class="icon" aria-hidden="true" src="assets/icons/trash.svg" />
{{ 'dates.remove' | translate }} {{ id + 1 }}

View File

@ -131,7 +131,7 @@ export class DayListComponent {
}
addChoice(optionalLabel = ''): void {
let lastDateChoice = this.pollService.dateChoiceList[this.pollService.dateChoiceList.length];
let lastDateChoice = this.pollService.dateChoiceList[this.pollService.dateChoiceList.length - 1];
console.log('lastDateChoice', lastDateChoice);
let lastDateChoiceObject = this.dateUtilitiesService.addDaysToDate(
this.pollService.dateChoiceList.length,
@ -149,29 +149,29 @@ export class DayListComponent {
this.pollService.dateChoiceList.sort((a: any, b: any) => {
return a.date_object - b.date_object;
});
this.focusOnChoice(this.storageService.dateChoices.length - 1);
this.cd.detectChanges();
this.focusOnChoice(this.pollService.dateChoiceList.length - 1);
}
focusOnChoice(index): void {
const selector = '#choice_label_' + index;
const selector = '#dateChoices_' + index;
const elem = this.document.querySelector(selector);
console.log('focusOnChoice elem', selector, elem);
if (elem) {
elem.focus();
}
}
deleteChoiceField(index: number): void {
if (this.dateChoices.length !== 1) {
this.dateChoices.splice(index, 1);
}
this.dateChoices.splice(index, 1);
this.cd.detectChanges();
this.focusOnChoice(index - 1 < 0 ? 0 : index - 1);
}
isWeekendDay(date_input: string) {
let date_object = new Date(Date.parse(date_input));
console.log('date_object', date_object);
if (date_object) {
const day = date_object.getDay();
console.log('day', day);
return day === 6 || day === 0;
}
return false;