Hi Folks,

I want to display error message after submit. Here is my code as below.

@Component({
    selector: 'field-error-display',
    templateUrl: 'fieldErrorDisplay.component.html',
    styleUrls: ['fieldErrorDisplay.component.css']
})


export class FieldErrorDisplayComponent {


    @Input() errorMsg: string;
    @Input() displayError: boolean;
}  


<div *ngIf="displayError">
    <div class="error-msg">
        <span class="fa fa-close" style="position:relative;top:4px"></span
>{{ errorMsg }}
    </div>
</div>


isFieldValid(field: string) {
 return !this.form.get(field).valid && this.form.get(field).touched;
}  
  
validateAllFormFields(formGroup: FormGroup): void {
    Object.keys(formGroup.controls).forEach(field => {
        const control = formGroup.get(field);
        if (control instanceof FormControl) {
            control.markAsTouched({ onlySelf: true });
        } else if (control instanceof FormGroup) {
            this.validateAllFormFields(control);
        }
    });
}  
  
<field-error-display [displayError]="isFieldValid('model')" errorMsg="Please 
enter a valid type of vehicle!"></field-error-display>
<p-dropdown [options]="modelVehicleDropDownList" [(ngModel)]=
"selectModelVehicle" placeholder="Select Vehicle" formControlName="model" 
filter="filter"></p-dropdown>


<https://lh3.googleusercontent.com/-3g6MIm6zxW4/Wm8G6JRfhEI/AAAAAAAAM0A/QAwfJ3HqxCoRboEZtLY49ZqgNAFpAcH8gCLcBGAs/s1600/Forum.PNG>


In the above screenshot, I just clicked dropdown list without any select 
value then got display error message. The error message should not display 
because i did not select any value from dropdown list. Other input are fine 
such as text and radio button. 

I tried many times still no clue. :(
Any idea?

I am waiting for your response.
Thanks in Advance

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to