Input: Extend enter - before unfocus. Range-Filder: Add on enter method, in order to change year range on search.

This commit is contained in:
Konstantinos Triantafyllou 2023-05-12 17:24:27 +03:00
parent 10178c5adb
commit 123f355344
3 changed files with 20 additions and 14 deletions

View File

@ -381,6 +381,9 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
@HostListener('window:keydown.enter', ['$event']) @HostListener('window:keydown.enter', ['$event'])
enter(event: KeyboardEvent) { enter(event: KeyboardEvent) {
if (this.extendEnter) {
this.extendEnter();
}
if (this.opened && this.optionBox) { if (this.opened && this.optionBox) {
event.preventDefault(); event.preventDefault();
if (this.filteredOptions[this.selectedIndex]) { if (this.filteredOptions[this.selectedIndex]) {
@ -391,9 +394,6 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
} else { } else {
this.focus(false, event); this.focus(false, event);
} }
if (this.extendEnter) {
this.extendEnter();
}
} }
@HostListener('keydown', ['$event']) @HostListener('keydown', ['$event'])

View File

@ -10,9 +10,9 @@
<div> <div>
<div class = "uk-animation-fade filterItem searchFilterItem uk-text-small"> <div class = "uk-animation-fade filterItem searchFilterItem uk-text-small">
<div class="searchFilterBoxValues "> <div class="searchFilterBoxValues ">
<div class="uk-width-4-5" input [formInput]="rangeForm" type="year-range" [yearRange]="yearRange" inputClass="flat small"> <div #input class="uk-width-4-5" input [formInput]="rangeForm" type="year-range" [yearRange]="yearRange" [extendEnter]="onEnter" inputClass="flat small">
<div action (click)="yearChanged()" class="action-icon" <div action (click)="yearChanged()" class="action-icon"
[class.disabled]="isDisabled || rangeForm.invalid || (!rangeForm.get('yearFrom').dirty && !rangeForm.get('yearTo').dirty) || rangeForm.get('yearFrom').invalid || rangeForm.get('yearTo').invalid"> [class.disabled]="disabled">
<icon name="chevron_right" [flex]="true"></icon> <icon name="chevron_right" [flex]="true"></icon>
<span class="visually-hidden">GO</span> <span class="visually-hidden">GO</span>
</div> </div>

View File

@ -1,10 +1,10 @@
import {Component, EventEmitter, Input, Output} from '@angular/core'; import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core';
import {RangeFilter} from './rangeFilterHelperClasses.class'; import {RangeFilter} from './rangeFilterHelperClasses.class';
import {Dates, StringUtils} from "../string-utils.class"; import {Dates, StringUtils} from "../string-utils.class";
import {ActivatedRoute, Router} from "@angular/router"; import {ActivatedRoute, Router} from "@angular/router";
import {properties} from "../../../../environments/environment"; import {properties} from "../../../../environments/environment";
import {UntypedFormBuilder, UntypedFormGroup} from "@angular/forms"; import {UntypedFormBuilder, UntypedFormGroup} from "@angular/forms";
import {YearRange} from "../../sharedComponents/input/input.component"; import {InputComponent, YearRange} from "../../sharedComponents/input/input.component";
@Component({ @Component({
selector: 'range-filter', selector: 'range-filter',
@ -17,7 +17,6 @@ export class RangeFilterComponent {
@Input() isDisabled:boolean = false; @Input() isDisabled:boolean = false;
@Input() showQuickButtons:boolean = true; @Input() showQuickButtons:boolean = true;
public _maxCharacters:number =28; public _maxCharacters:number =28;
public focusedInput: string = "";
@Input() yearMin: number = Dates.yearMin; @Input() yearMin: number = Dates.yearMin;
@Input() yearMax: number = Dates.yearMax; @Input() yearMax: number = Dates.yearMax;
@Input() mandatoryRange:boolean = false; @Input() mandatoryRange:boolean = false;
@ -29,10 +28,16 @@ export class RangeFilterComponent {
from: {control: 'yearFrom', placeholder: this.yearMin.toString()}, from: {control: 'yearFrom', placeholder: this.yearMin.toString()},
to: {control: 'yearTo', placeholder: this.yearMax.toString()} to: {control: 'yearTo', placeholder: this.yearMax.toString()}
} }
@Output() onFilterChange = new EventEmitter(); @Output() onFilterChange = new EventEmitter();
@Input() actionRoute:boolean = false; @Input() actionRoute:boolean = false;
@ViewChild('input') input: InputComponent;
queryParams = {}; queryParams = {};
onEnter: () => void = () => {
if(!this.disabled) {
this.yearChanged();
}
}
constructor(private _router: Router, private route: ActivatedRoute, private _fb: UntypedFormBuilder) {} constructor(private _router: Router, private route: ActivatedRoute, private _fb: UntypedFormBuilder) {}
ngOnInit() { ngOnInit() {
@ -51,6 +56,12 @@ export class RangeFilterComponent {
public _formatTitle(title){ public _formatTitle(title){
return ((title.length > this._maxCharacters)?(title.substring(0,(this._maxCharacters - ('...').length))+"..."):title); return ((title.length > this._maxCharacters)?(title.substring(0,(this._maxCharacters - ('...').length))+"..."):title);
} }
get disabled() {
return this.isDisabled || this.rangeForm.invalid ||
(!this.rangeForm.get('yearFrom').dirty && !this.rangeForm.get('yearTo').dirty) ||
this.rangeForm.get('yearFrom').invalid || this.rangeForm.get('yearTo').invalid
}
yearChanged(yearsSelected: number = null){ yearChanged(yearsSelected: number = null){
if(yearsSelected != null) { if(yearsSelected != null) {
@ -72,16 +83,11 @@ export class RangeFilterComponent {
this.filter.selectedToValue = null; this.filter.selectedToValue = null;
this.rangeForm.get('yearFrom').setValue(this.filter.selectedFromValue); this.rangeForm.get('yearFrom').setValue(this.filter.selectedFromValue);
this.rangeForm.get('yearTo').setValue(this.filter.selectedToValue); this.rangeForm.get('yearTo').setValue(this.filter.selectedToValue);
console.log(this.rangeForm);
this.onFilterChange.emit({ this.onFilterChange.emit({
value: this.filter value: this.filter
}); });
} }
getFilterName(value){
return value.name + " (" + value.number.format() + ")";
}
stringToNum(value: string): number { stringToNum(value: string): number {
return +(value); return +(value);
} }