Input: Fix arrow left-right on inputs with type != chips. Fix dirty status of from and to controls for year-range type.
This commit is contained in:
parent
7cf23698d7
commit
99492a2f08
|
@ -353,9 +353,9 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
|||
|
||||
@HostListener('window:keydown.arrowLeft', ['$event'])
|
||||
arrowLeft(event: KeyboardEvent) {
|
||||
if (this.focused) {
|
||||
event.preventDefault();
|
||||
if (this.type === 'chips' && this.focused) {
|
||||
if (this.activeElement.getValue()) {
|
||||
event.preventDefault();
|
||||
let index = this.chips.toArray().indexOf(this.activeElement.getValue());
|
||||
if (index > 0) {
|
||||
this.activeElement.next(this.chips.get(index - 1));
|
||||
|
@ -367,9 +367,9 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
|||
|
||||
@HostListener('window:keydown.arrowRight', ['$event'])
|
||||
arrowRight(event: KeyboardEvent) {
|
||||
if (this.focused) {
|
||||
event.preventDefault();
|
||||
if (this.type === 'chips' && this.focused) {
|
||||
if (this.activeElement.getValue()) {
|
||||
event.preventDefault();
|
||||
let index = this.chips.toArray().indexOf(this.activeElement.getValue());
|
||||
if (index < this.chips.length - 1) {
|
||||
this.activeElement.next(this.chips.get(index + 1));
|
||||
|
@ -544,20 +544,22 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
|||
}
|
||||
this.subscriptions.push(this.formControl.valueChanges.subscribe(value => {
|
||||
if (this.formControl.enabled) {
|
||||
value = (value === '') ? null : value;
|
||||
if (this.type === 'logoURL') {
|
||||
this.secure = (!value || value.includes('https://'));
|
||||
}
|
||||
if (this.initValue === value || (this.initValue === '' && value === null)) {
|
||||
this.formControl.markAsPristine();
|
||||
} else {
|
||||
this.formControl.markAsDirty();
|
||||
}
|
||||
if (this.type === 'autocomplete_soft') {
|
||||
this.filteredOptions = this.filter(value);
|
||||
this.cdr.detectChanges();
|
||||
if (this.focused) {
|
||||
this.open(true);
|
||||
if(this.type !== 'year-range') {
|
||||
value = (value === '') ? null : value;
|
||||
if (this.type === 'logoURL') {
|
||||
this.secure = (!value || value.includes('https://'));
|
||||
}
|
||||
if (this.initValue === value || (this.initValue === '' && value === null)) {
|
||||
this.formControl.markAsPristine();
|
||||
} else {
|
||||
this.formControl.markAsDirty();
|
||||
}
|
||||
if (this.type === 'autocomplete_soft') {
|
||||
this.filteredOptions = this.filter(value);
|
||||
this.cdr.detectChanges();
|
||||
if (this.focused) {
|
||||
this.open(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((this.value && value && this.value !== value) || (!this.value && value) || this.value && !value) {
|
||||
|
@ -566,14 +568,30 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
|||
}
|
||||
}));
|
||||
if(this.formAsGroup) {
|
||||
this.subscriptions.push(this.formAsGroup.get(this.yearRange.from.control).valueChanges.subscribe(value => {
|
||||
if(this.formAsGroup.get(this.yearRange.from.control).valid) {
|
||||
if(this.activeIndex === 0 && value.length > 0) {
|
||||
let fromControl = this.formAsGroup.get(this.yearRange.from.control);
|
||||
this.subscriptions.push(fromControl.valueChanges.subscribe(value => {
|
||||
let from = this.initValue[this.yearRange.from.control];
|
||||
if (from === value || (from === '' && value === null)) {
|
||||
fromControl.markAsPristine();
|
||||
} else {
|
||||
fromControl.markAsDirty();
|
||||
}
|
||||
if(fromControl.valid) {
|
||||
if(this.activeIndex === 0 && value) {
|
||||
this.activeIndex = 1;
|
||||
this.input.get(this.activeIndex).nativeElement.focus();
|
||||
}
|
||||
}
|
||||
}));
|
||||
let toControl = this.formAsGroup.get(this.yearRange.to.control);
|
||||
this.subscriptions.push(toControl.valueChanges.subscribe(value => {
|
||||
let to = this.initValue[this.yearRange.to.control];
|
||||
if (to === value || (to === '' && value === null)) {
|
||||
toControl.markAsPristine();
|
||||
} else {
|
||||
toControl.markAsDirty();
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (this.input) {
|
||||
this.input.forEach(input => {
|
||||
|
|
Loading…
Reference in New Issue