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

Control resetOnHide for a specific field #2570

Closed
Suraj786 opened this issue Oct 28, 2020 · 16 comments · Fixed by #2721
Closed

Control resetOnHide for a specific field #2570

Suraj786 opened this issue Oct 28, 2020 · 16 comments · Fixed by #2721

Comments

@Suraj786
Copy link

Description
Hideexpression is not working with repeat and ngx-datatable control

demo link

Your Environment

  • Angular version: 8.1.2
  • Formly version: 5.10.5

Additional context
Even we have nested hideexpression inside repeat control.
Can you please help me find a solution.

Thanks in advance.

@Suraj786 Suraj786 added the bug label Oct 28, 2020
@aitboudad aitboudad added question and removed bug labels Oct 31, 2020
@aitboudad
Copy link
Member

The passed model value for fieldArray and fieldGroup is the scoped one, what you're looking for is the root model which can be accessed using field.parent.model #704 (comment)

@Suraj786
Copy link
Author

Suraj786 commented Nov 4, 2020

Thanks for the reply,

Now I have added the field.parent.model but if you see when we switch radio button options 2-3 times then datatable's initial values will disappear.
Even on repeater if you click on add another then nested hideexpression wont work in that case.

updated demo link - https://stackblitz.com/edit/angular-nbze38-retv6u

can you please have a look at this scenario.

Thanks in advance.

@aitboudad
Copy link
Member

I think that's expected behavior when resetFieldOnHide is enabled as Formly expected a valid initial model value (when the radio button is empty the data table data should be empty).

@Suraj786
Copy link
Author

Suraj786 commented Dec 4, 2020

Hi @aitboudad

Can we have feature like autoClear: false for control level where we don't reset for few selected control when on module we have resetFieldOnHide: true.
So on above example datatable can retain its initial values.

OR

Is there any way to handle this scenario using prePopulate, onPopulate and postPopulate.

Can you please have a look at this scenario.
Thanks in advance.

@Suraj786
Copy link
Author

Suraj786 commented Dec 9, 2020

Hi @aitboudad

Can you please help me out on above commented scenario. Sorry for bothering you but I am stuck on that issue.
Above comment

Thanks in advance.

@aitboudad
Copy link
Member

did you try to pass autoClear: false, its an internal feature which we may expose later

@Suraj786
Copy link
Author

Hi @aitboudad

Yes, I have tried adding autoClear: false but its showing below error.
Object literal may only specify known properties, and autoClear does not exist in type FormlyFieldConfig.

Even after removing FormlyFieldConfig type its not working.

I am using Formly version: 5.10.5

Thanks in advance.

@aitboudad
Copy link
Member

it's not part of FormlyFieldConfig yet also make sure to pass it to all field children as it doesn't take account of the parent state.

@Suraj786
Copy link
Author

Hi @aitboudad

I have tried that also, it's not working. Might be I'm doing something wrong. Can you please update on this
Demo Link

Thanks in advance.

@aitboudad
Copy link
Member

added a fix in 5.10.8, instead of autoClear use resetOnHide but still a hidden feature.

@Suraj786
Copy link
Author

Hi @aitboudad

It's working fine as expected.
Thanks for the update and fixes.

@Suraj786
Copy link
Author

Hi @aitboudad

Found other issue after package update. We have checkbox on datatable row. based on selection we are enabling remaining column data. But looks like there is some issue with your recent checkbox update.
Sample Link

Can you please have a look.
Thanks in advance.

@aitboudad
Copy link
Member

that's a bug I'll try to fix it in the next release, for a workaround:

{
  type: "checkbox",
  key: "investmentDate",
+  expressionProperties: {
+    ["templateOptions.disabled"]: "false"
+  }
},

@aitboudad
Copy link
Member

pushed a fix for disabled state issue in 5.10.9

@aitboudad aitboudad changed the title Hideexpression is not working with repeat and ngx-datatable control Control resetOnHide for a specific field Dec 16, 2020
@KamilSocha91
Copy link

This should be closed issue?

@aitboudad
Copy link
Member

not yet, still not part of the public API.

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

Successfully merging a pull request may close this issue.

3 participants