- Home
- Forum
- Angular - EJ 2
- What's the preferred way to show server side validation messages
What's the preferred way to show server side validation messages
Hello!
We have server side validation in our code and now my question is how I should show them on e.g. a textbox.
Currently I found a way of just rendering a div below the textbox with class e-error and the messages in it.
What is the intended way of doing this?
I would somehow prefer that the textbox component checks the control for errors (as I add them programmatically) and shows them.
Or the other way would be to allow custom content inside ejs-textbox which renders just after the textbox, so I can inject formControlName in a custom directive.
I'm just unhappy that I need to write "lastname" multiple times.
Example code of my current solution:
error.error.violations.forEach(violation => {
const validationErrors: ValidationErrors = {};
validationErrors[violation.message] = true;
contactForm.controls[violation.field].setErrors(validationErrors);
})
<ejs-textbox placeholder="Last Name" floatLabelType="Auto" formControlName="lastname"
[cssClass]="validation.determineValidationClass(contactForm,'lastname')"></ejs-textbox>
<div class="e-error" *ngIf="hasError(contactForm, 'lastname')">
{{ getErrorMessage(contactForm, 'lastname') }}
</div>
Hi Christopher,
Your links describe frontend validation (form validators), but I have backend validation messages which I want to show below their corresponding control.
But as I see from frontend validation I need to manually add a div with e-error class to show the messages and thats it, right?
My preferred solution would be:
The textbox reads the errors from its connected control, shows them automagically and also renders the e-error class to highlight itself.
Is this a valid feature request, if it doesn't exist this way?
- 3 Replies
- 2 Participants
-
MR Marcel Ring
- Aug 16, 2021 05:55 AM UTC
- Aug 19, 2021 01:47 PM UTC