0

I have created a custom tab in system config and added 1 field Module Enable Yes/No and 1 Dynamic fields which is depends on Module Enable.

When Module Enable is set Yes I created various dynamic fields and save it. which works fine.

When module is set to No and save after page reload all of my dynamic rows are gone. I using a Plugin and aroundSave Method.

The reason is when is set to no the data from dynamic fields does not get send in the post. see post value from Plugin:

Array
(
    [section] => custom_system_config
    [website] => 
    [store] => 
    [groups] => Array
        (
            [general] => Array
                (
                    [fields] => Array
                        (
                            [enable] => Array
                                (
                                    [value] => 0
                                )

                            [filter] => Array
                                (
                                    [value] => Array
                                        (
                                            [__empty] => 
                                        )

                                )

                        )

                )

        )

)

Dynamics Fields have depend on module enable field:

...
<depends>
  <field id="enable">1</field>
</depends>
...

The filter should have an array with fields.

In My Plugin How can I not save the data if enable is set to No?

Because this is still saving empty values obviously.

Appreciate any help!

4
  • please share your plugin code – Rendy Eko Prastiyo Aug 15 '19 at 0:12
  • @RendyEkoPrastiyo thanks fo the interest I've resolved my issue by just removing the depends from system.xml and use javascript whether to show or hide based on Yes/No. – Juliano Vargas Aug 15 '19 at 9:12
  • Good to see that you have solved this. What you explained in your issue is the default behavior of Magento config management. If your parent condition does not meet the requirement of dependent children (which then the children inputs will be hidden), your children values will be deleted from the config data stored in database (core_config_data). – Rendy Eko Prastiyo Aug 15 '19 at 10:57
  • @RendyEkoPrastiyo No. Not in all the cases e.g: input text fields I've tested it and doesn't delete nor even a file upload or select. My only issue is with Dynamic fields that Depends on Yes/No field. I've seen in the Dom that magento not only display none only but also add attr disabled to the dynamic fields. – Juliano Vargas Aug 15 '19 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.