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

Angular Material - validation message not showing if required set dynamically #2106

Closed
Gobikannan opened this issue Feb 19, 2020 · 7 comments · Fixed by #2107
Closed

Angular Material - validation message not showing if required set dynamically #2106

Gobikannan opened this issue Feb 19, 2020 · 7 comments · Fixed by #2107
Labels

Comments

@Gobikannan
Copy link

First of all, thanks alot for the awesome library. It is easy to configure and flexible to modify as we want.

I have an requirement to set field2 as required based on field1. It works absolutely fine but validation message doesn't show properly. Here is the simple example which I have created,

stackblitz

Steps to reproduce:

  1. Enter something on field1 and it shows asterik (*) on field2 but it doesn't show the message as Field required.
  2. I tried clicking on the field2 but still it doesn't show message.

I am not sure if this is something to do with Angular material.

@Gobikannan
Copy link
Author

Thanks @aitboudad.. when will be this available?

@aitboudad
Copy link
Member

up to Monday

@Gobikannan
Copy link
Author

Thanks @aitboudad, that's pretty quick..

@aitboudad
Copy link
Member

This issue has been fixed and released as part of v5.5.13 release.

Please let us know, in case you are still encountering a similar issue/problem.
Thank you!

@Gobikannan
Copy link
Author

Thanks @aitboudad.. Now it shows validation message but it doesn't hide once it is shown.

I have updated the packages on same sample link - https://stackblitz.com/edit/ngx-formly-validation-msg

If i add some test to field1 then field2 show mandatory () and if focus on field2, then it shows validation message but it doesn't hide the validation message and shows red even if i remove values from field1 (which is not mandatory - but removes () from field2)..

Is it something you can take a look please? let me know if you need more details on replicating it.

Thanks.

@aitboudad aitboudad reopened this Feb 21, 2020
@aitboudad
Copy link
Member

required expects a boolean value, try with:

expressionProperties: {
  'templateOptions.required': (model: any, formState: any, fieldConfig: FormlyFieldConfig) => {
+    return !!model.field1;
-    return model.field1;
  },
}

@Gobikannan
Copy link
Author

Ofcourse.. Thanks, it works fine on our code.
Cheers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants