Input: Extend enter - before unfocus. Range-Filder: Add on enter method, in order to change year range on search.
This commit is contained in:
parent
10178c5adb
commit
123f355344
|
@ -381,6 +381,9 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
|||
|
||||
@HostListener('window:keydown.enter', ['$event'])
|
||||
enter(event: KeyboardEvent) {
|
||||
if (this.extendEnter) {
|
||||
this.extendEnter();
|
||||
}
|
||||
if (this.opened && this.optionBox) {
|
||||
event.preventDefault();
|
||||
if (this.filteredOptions[this.selectedIndex]) {
|
||||
|
@ -391,9 +394,6 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
|||
} else {
|
||||
this.focus(false, event);
|
||||
}
|
||||
if (this.extendEnter) {
|
||||
this.extendEnter();
|
||||
}
|
||||
}
|
||||
|
||||
@HostListener('keydown', ['$event'])
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
<div>
|
||||
<div class = "uk-animation-fade filterItem searchFilterItem uk-text-small">
|
||||
<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"
|
||||
[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>
|
||||
<span class="visually-hidden">GO</span>
|
||||
</div>
|
||||
|
|
|
@ -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 {Dates, StringUtils} from "../string-utils.class";
|
||||
import {ActivatedRoute, Router} from "@angular/router";
|
||||
import {properties} from "../../../../environments/environment";
|
||||
import {UntypedFormBuilder, UntypedFormGroup} from "@angular/forms";
|
||||
import {YearRange} from "../../sharedComponents/input/input.component";
|
||||
import {InputComponent, YearRange} from "../../sharedComponents/input/input.component";
|
||||
|
||||
@Component({
|
||||
selector: 'range-filter',
|
||||
|
@ -17,7 +17,6 @@ export class RangeFilterComponent {
|
|||
@Input() isDisabled:boolean = false;
|
||||
@Input() showQuickButtons:boolean = true;
|
||||
public _maxCharacters:number =28;
|
||||
public focusedInput: string = "";
|
||||
@Input() yearMin: number = Dates.yearMin;
|
||||
@Input() yearMax: number = Dates.yearMax;
|
||||
@Input() mandatoryRange:boolean = false;
|
||||
|
@ -29,10 +28,16 @@ export class RangeFilterComponent {
|
|||
from: {control: 'yearFrom', placeholder: this.yearMin.toString()},
|
||||
to: {control: 'yearTo', placeholder: this.yearMax.toString()}
|
||||
}
|
||||
|
||||
@Output() onFilterChange = new EventEmitter();
|
||||
@Input() actionRoute:boolean = false;
|
||||
@ViewChild('input') input: InputComponent;
|
||||
queryParams = {};
|
||||
onEnter: () => void = () => {
|
||||
if(!this.disabled) {
|
||||
this.yearChanged();
|
||||
}
|
||||
}
|
||||
|
||||
constructor(private _router: Router, private route: ActivatedRoute, private _fb: UntypedFormBuilder) {}
|
||||
|
||||
ngOnInit() {
|
||||
|
@ -51,6 +56,12 @@ export class RangeFilterComponent {
|
|||
public _formatTitle(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){
|
||||
if(yearsSelected != null) {
|
||||
|
@ -72,16 +83,11 @@ export class RangeFilterComponent {
|
|||
this.filter.selectedToValue = null;
|
||||
this.rangeForm.get('yearFrom').setValue(this.filter.selectedFromValue);
|
||||
this.rangeForm.get('yearTo').setValue(this.filter.selectedToValue);
|
||||
console.log(this.rangeForm);
|
||||
this.onFilterChange.emit({
|
||||
value: this.filter
|
||||
});
|
||||
}
|
||||
|
||||
getFilterName(value){
|
||||
return value.name + " (" + value.number.format() + ")";
|
||||
}
|
||||
|
||||
stringToNum(value: string): number {
|
||||
return +(value);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue