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

Hide expression on repeat component breaks defaultValues of nested fields #3891

Closed
gaetanlgce opened this issue Apr 4, 2024 · 5 comments · Fixed by #3924
Closed

Hide expression on repeat component breaks defaultValues of nested fields #3891

gaetanlgce opened this issue Apr 4, 2024 · 5 comments · Fixed by #3924
Labels

Comments

@gaetanlgce
Copy link

Description
When using expressions.hide on a custom repeating section to conditionnally display it, defaultValue is ignored in fields in the fieldGroup. If the expressions.hide is not present, default values are applied as expected when adding items.

Minimal Reproduction
https://stackblitz.com/edit/angular-e9plpt?file=src%2Fapp%2Fapp.component.ts,src%2Fapp%2Frepeat-section.type.ts,src%2Fstyles.scss,src%2Fapp%2Fapp.component.html

In this example, the defaultValue: 'Buy eggs', is not applied as expected because there is the hide expression line 46.

Your Environment

  • Angular version: 14.3.0
  • Formly version: 6.3.0

Additional context
It's maybe related to that issue #2651

@gaetanlgce gaetanlgce added the bug label Apr 4, 2024
@uagrawal-evertz
Copy link

uagrawal-evertz commented Apr 19, 2024

I am also facing similar kind of issue.
@aitboudad is there any resolution to fix this ?

@aitboudad
Copy link
Member

@aitboudad is there any resolution to fix this ?

Hi, I'll this week if time allows 🙏 .

@aitboudad
Copy link
Member

This issue has been fixed and released as part of v6.3.2 release.

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

@uagrawal-evertz
Copy link

uagrawal-evertz commented Jun 10, 2024

Hello @aitboudad , Thanks for looking in to this bug.

In our case, We are facing slightly diff issue..We have Json schema, in which we are applying some patches, which contains hide expression on some fields
for example: below fields are wrap inside an type = array field with minItems:1

bitrate: { expressions: { hide: (field: FormlyFieldConfig | undefined) => { return false; } } }, definition: { expressions: { hide: (field: FormlyFieldConfig | undefined) => { return false; } } }

In schema these fields have defaultValue as well.

But when form renders initially, fields which contains hide expression their default value gets overridden in someway and those fields does not appear in main model (Hence empty fields renders even those have defaultValues). if we add new items in array those hidden fields appear with their defaultValue.

So I am not sure what is causing such issue, Do you have any suggestion on what is wrong here ?

@aitboudad
Copy link
Member

@uagrawal-evertz please open a new ticket with a reproduction example so we may be able to check it further.

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.

3 participants