Ngx-formly: Control resetOnHide for a specific field

Created on 28 Oct 2020  路  16Comments  路  Source: ngx-formly/ngx-formly

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.

enhancement

All 16 comments

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 https://github.com/ngx-formly/ngx-formly/issues/704#issuecomment-364661614

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.

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).

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.

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.

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

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.

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.

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.

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

Hi @aitboudad

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

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.

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"
+  }
},

pushed a fix for disabled state issue in 5.10.9

This should be closed issue?

not yet, still not part of the public API.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smile2014 picture smile2014  路  17Comments

hariharan614 picture hariharan614  路  20Comments

smile2014 picture smile2014  路  19Comments

ThrownLemon picture ThrownLemon  路  24Comments

enricooliva picture enricooliva  路  16Comments