Skip to content
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

Hints and error messages for value inputs #32

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,6 +1,16 @@
<span [formGroup]="form">
<mat-form-field class="large-field">
<input matInput [formControlName]="'decimalValue'" class="value" placeholder="Decimal value" type="number" [readonly]="mode === 'read'">
<input matInput #inputValue [formControlName]="'decimalValue'" class="value" placeholder="Decimal value" type="number" [readonly]="mode === 'read'">
<mat-hint>Enter a decimal value</mat-hint>
<mat-error *ngIf="valueFormControl.hasError('required')">
A value is required
</mat-error>
<mat-error *ngIf="valueFormControl.hasError('valueNotChanged')">
Value must be different
</mat-error>
<mat-error *ngIf="valueFormControl.hasError('pattern')">
Please enter a valid decimal
</mat-error>
</mat-form-field>
<mat-form-field class="large-field">
<input matInput [formControlName]="'comment'" class="comment" placeholder="Comment" type="text" [readonly]="mode === 'read'">
Expand Down
@@ -1,4 +1,4 @@
import {Component, Inject, Input, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core';
import {Component, Inject, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ElementRef} from '@angular/core';
import {BaseValueComponent} from '../base-value.component';
import {CreateDecimalValue, ReadDecimalValue, UpdateDecimalValue} from '@knora/api';
import {Subscription} from 'rxjs';
Expand All @@ -12,6 +12,7 @@ import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
export class DecimalValueComponent extends BaseValueComponent implements OnInit, OnChanges, OnDestroy {

@Input() displayValue?: ReadDecimalValue;
@ViewChild('inputValue', {static: false}) inputValueRef: ElementRef;

valueFormControl: FormControl;
commentFormControl: FormControl;
Expand Down Expand Up @@ -56,6 +57,9 @@ export class DecimalValueComponent extends BaseValueComponent implements OnInit,
}

ngOnChanges(changes: SimpleChanges): void {
if(this.mode != 'read' && this.inputValueRef !== undefined){
this.inputValueRef.nativeElement.focus();
}
this.resetFormControl();
}

Expand Down
@@ -1,6 +1,16 @@
<span [formGroup]="form">
<mat-form-field class="large-field">
<input matInput [formControlName]="'intValue'" class="value" placeholder="Int value" type="number" [readonly]="mode === 'read'">
<input matInput #inputValue [formControlName]="'intValue'" class="value" placeholder="Int value" type="number" [readonly]="mode === 'read'">
<mat-hint>Enter an integer value</mat-hint>
<mat-error *ngIf="valueFormControl.hasError('required')">
A value is required
</mat-error>
<mat-error *ngIf="valueFormControl.hasError('valueNotChanged')">
Value must be different
</mat-error>
<mat-error *ngIf="valueFormControl.hasError('pattern')">
Please enter a valid integer
</mat-error>
</mat-form-field>
<mat-form-field class="large-field">
<input matInput [formControlName]="'comment'" class="comment" placeholder="Comment" type="text" [readonly]="mode === 'read'">
Expand Down
@@ -1,4 +1,4 @@
import {Component, Inject, Input, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core';
import {Component, Inject, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ElementRef} from '@angular/core';
import {BaseValueComponent} from '../base-value.component';
import {CreateIntValue, ReadIntValue, UpdateIntValue} from '@knora/api';
import {Subscription} from 'rxjs';
Expand All @@ -13,6 +13,7 @@ import {CustomRegex} from '../custom-regex';
export class IntValueComponent extends BaseValueComponent implements OnInit, OnChanges, OnDestroy {

@Input() displayValue?: ReadIntValue;
@ViewChild('inputValue', {static: false}) inputValueRef: ElementRef;

valueFormControl: FormControl;
commentFormControl: FormControl;
Expand Down Expand Up @@ -57,6 +58,9 @@ export class IntValueComponent extends BaseValueComponent implements OnInit, OnC
}

ngOnChanges(changes: SimpleChanges): void {
if(this.mode != 'read' && this.inputValueRef !== undefined){
this.inputValueRef.nativeElement.focus();
}
this.resetFormControl();
}

Expand Down
@@ -1,6 +1,6 @@
<div [formGroup]="form" class="interval-input-container">
<mat-form-field>
<input matInput class="interval-input-element start" [formControlName]="'start'" type="number" aria-label="start" [readonly]="readonly" (input)="_handleInput()" [placeholder]="intervalStartLabel" [errorStateMatcher]="matcher">
<input matInput #inputValueStart class="interval-input-element start" [formControlName]="'start'" type="number" aria-label="start" [readonly]="readonly" (input)="_handleInput()" [placeholder]="intervalStartLabel" [errorStateMatcher]="matcher">
<mat-error *ngIf="form.controls.start.hasError('required')">
Start is <strong>required</strong>
</mat-error>
Expand Down
@@ -1,4 +1,4 @@
import {Component, DoCheck, ElementRef, HostBinding, Input, OnDestroy, Optional, Self} from '@angular/core';
import {Component, DoCheck, ElementRef, HostBinding, Input, OnDestroy, Optional, Self, ViewChild} from '@angular/core';
import {MatFormFieldControl} from '@angular/material/form-field';
import {ControlValueAccessor, FormBuilder, FormControl, FormGroup, FormGroupDirective, NgControl, NgForm, Validators} from '@angular/forms';
import {Subject} from 'rxjs';
Expand Down Expand Up @@ -59,6 +59,8 @@ export class IntervalInputComponent extends _MatInputMixinBase implements Contro
@Input() intervalStartLabel = 'start';
@Input() intervalEndLabel = 'end';

@ViewChild('inputValueStart', {static: false}) inputValueRef: ElementRef;

get empty() {
const userInput = this.form.value;
return !userInput.start && !userInput.end;
Expand Down Expand Up @@ -161,6 +163,9 @@ export class IntervalInputComponent extends _MatInputMixinBase implements Contro

ngDoCheck() {
if (this.ngControl) {
if(this.inputValueRef !== undefined){
this.inputValueRef.nativeElement.focus();
}
this.updateErrorState();
}
}
Expand Down
@@ -1,6 +1,13 @@
<span [formGroup]="form">
<mat-form-field class="large-field">
<input matInput [formControlName]="'textValue'" class="value" placeholder="Text value" type="text" [readonly]="mode === 'read'">
<input matInput #inputValue [formControlName]="'textValue'" class="value" placeholder="Text value" type="text" [readonly]="mode === 'read'">
<mat-hint>Enter a text value</mat-hint>
<mat-error *ngIf="valueFormControl.hasError('required')">
A value is required
</mat-error>
<mat-error *ngIf="valueFormControl.hasError('valueNotChanged')">
Value must be different
</mat-error>
</mat-form-field>
<mat-form-field class="large-field">
<input matInput [formControlName]="'comment'" class="comment" placeholder="Comment" type="text" [readonly]="mode === 'read'">
Expand Down
@@ -1,4 +1,4 @@
import {Component, Inject, Input, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core';
import {Component, Inject, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ElementRef} from '@angular/core';
import {BaseValueComponent} from '../../base-value.component';
import {CreateTextValueAsString, ReadTextValueAsString, UpdateTextValueAsString} from '@knora/api';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
Expand All @@ -12,6 +12,7 @@ import {Subscription} from 'rxjs';
export class TextValueAsStringComponent extends BaseValueComponent implements OnInit, OnChanges, OnDestroy {

@Input() displayValue?: ReadTextValueAsString;
@ViewChild('inputValue', {static: false}) inputValueRef: ElementRef;

valueFormControl: FormControl;
commentFormControl: FormControl;
Expand Down Expand Up @@ -57,7 +58,10 @@ export class TextValueAsStringComponent extends BaseValueComponent implements On
}

ngOnChanges(changes: SimpleChanges): void {

// if user is not in readonly mode, focus on the value input field
if(this.mode != 'read' && this.inputValueRef !== undefined){
this.inputValueRef.nativeElement.focus();
}
// resets values and validators in form controls when input displayValue or mode changes
// at the first call of ngOnChanges, form control elements are not initialized yet
this.resetFormControl();
Expand Down
@@ -1,6 +1,16 @@
<span [formGroup]="form">
<mat-form-field class="large-field">
<input matInput [formControlName]="'uriValue'" class="value" placeholder="Uri value" type="url" [readonly]="mode === 'read'">
<input matInput #inputValue [formControlName]="'uriValue'" class="value" placeholder="Uri value" type="url" [readonly]="mode === 'read'">
<mat-hint>Enter a URI</mat-hint>
<mat-error *ngIf="valueFormControl.hasError('required')">
A value is required
</mat-error>
<mat-error *ngIf="valueFormControl.hasError('valueNotChanged')">
Value must be different
</mat-error>
<mat-error *ngIf="valueFormControl.hasError('pattern')">
Please enter a valid URI
</mat-error>
</mat-form-field>
<mat-form-field class="large-field">
<input matInput [formControlName]="'comment'" class="comment" placeholder="Comment" type="text" [readonly]="mode === 'read'">
Expand Down
@@ -1,4 +1,4 @@
import {Component, Inject, Input, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core';
import {Component, Inject, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ElementRef} from '@angular/core';
import {BaseValueComponent} from '../base-value.component';
import {CreateUriValue, ReadUriValue, UpdateUriValue} from '@knora/api';
import {Subscription} from 'rxjs';
Expand All @@ -13,6 +13,7 @@ import {CustomRegex} from '../custom-regex';
export class UriValueComponent extends BaseValueComponent implements OnInit, OnChanges, OnDestroy {

@Input() displayValue?: ReadUriValue;
@ViewChild('inputValue', {static: false}) inputValueRef: ElementRef;

valueFormControl: FormControl;
commentFormControl: FormControl;
Expand Down Expand Up @@ -54,6 +55,9 @@ export class UriValueComponent extends BaseValueComponent implements OnInit, OnC
}

ngOnChanges(changes: SimpleChanges): void {
if(this.mode != 'read' && this.inputValueRef !== undefined){
this.inputValueRef.nativeElement.focus();
}
this.resetFormControl();
}

Expand Down