-
Notifications
You must be signed in to change notification settings - Fork 70
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
Validation Flaws in IxInput: Immediate Error Display and Documentation Workaround Problems #1638
Comments
I'd like to confirm the issue and propose a solution. The current implementation of the I propose the following solution:
Here's the modified code: ...
@Directive()
export class ValueAccessor
implements ControlValueAccessor, AfterViewInit, OnDestroy
{
public static readonly ANGULAR_CLASS_PREFIX = 'ng-';
private onChange: (value: any) => void = () => {
/**/
};
private onTouched: () => void = () => {
/**/
};
protected lastValue: any;
private statusChanges?: Subscription;
constructor(protected injector: Injector, protected elementRef: ElementRef) {}
writeValue(value: any): void {
this.elementRef.nativeElement.value = this.lastValue = value;
// Call mapNgToIxClassNames only when the value actually changes
if (value !== this.lastValue) {
mapNgToIxClassNames(this.elementRef);
}
}
handleValueChange(el: HTMLElement, value: any): void {
if (el === this.elementRef.nativeElement) {
if (value !== this.lastValue) {
this.lastValue = value;
this.onChange(value);
mapNgToIxClassNames(this.elementRef);
}
}
}
...
} |
🤖 Hello @Aiderlei Your issue will be analyzed and is part of our internal workflow. JIRA: IX-2284 |
Hello @Aiderlei! |
Hi @matthiashader, Thanks for the explanation and the Stackblitz example—it clarifies the behavior well! I’m glad to hear you’re looking into the CustomValidator issue and the suppress-initial-validation property. That said, this is currently blocking us, as achieving a good user experience requires extra workarounds. Resolving this would be a big help! Resolving this directly in the framework would make a big difference and save a lot of effort on our side. Looking forward to seeing the updates in the coming sprints. |
Prerequisites
Bug Report: Validation Flaws in IxInput: Immediate Error Display and Documentation Workaround Problems
Description
I have tested the new
IxInput
elements and discovered that the required form validation is displayed immediately upon the first render.This behavior is problematic because it does not allow for customization of validation behavior in forms, which is possible in pure Angular or other libraries. Typically, developers can customize when validation messages appear, such as by rendering them only after a field is touched or dirty.
Comparison with Angular Material
For reference, Angular Material provides an
errorStateMatcher
to tweak validation behavior. By default, Angular Material only displays validation messages when a field is dirty or touched. This provides better control and user experience.Problems with Suggested Workaround
The suggested workaround in the documentation introduces additional issues:
Incorrect Validation State:
Misleading Feedback Messages:
Buggy Behavior in Example Code:
!control.untouched
leads to unexpected behavior. For example:Adjusting the
CustomRequiredValidator
to rely on!pristine
is also insufficient, and conditionally setting validation messages does not resolve the issue, as it still displays incorrect valid feedback (refer to my repository for more details).Expected Behavior
The required validation messages for
IxInput
should:errorStateMatcher
.Suggested Solution
errorStateMatcher
.What type of frontend framework are you seeing the problem on?
Angular
Which version of iX do you use?
v2.6.1
Code to produce this issue.
I have created a github repository linked to stackblitz in the README to demonstrate these behaviors.
The demo shows four different examples of required fields, these are:
RequiredValidator
with therequired
HTML attribute. This demonstrates thatIxInput
is broken for theRequiredValidator
.CustomRequiredValidator
. This highlights that the suggested solution from the documentation is flawed, as it allows submission of an empty form and shows incorrect valid feedback.CustomRequiredValidator
from the documentation. This shows that adjusting theCustomRequiredValidator
to rely on!pristine
is insufficient and that setting validation messages conditionally does not resolve the issue.The text was updated successfully, but these errors were encountered: