Codeinwp / woocommerce-product-addon

PPOM for WooCommerce
4 stars 4 forks source link

Lock the field data name during editing the title #82

Open mskapusuz opened 1 year ago

mskapusuz commented 1 year ago

Currently, when you try to edit a field title; the dataname is changed as automatically. That's good for the fresh fields, but it's not good for editing the fields.

That dataname is saved in order item meta, therefore if the dataname of the field has been changed, it affects lots of places:

Screen Shot 2022-11-27 at 01 57 59 https://vertis.d.pr/i/pIi5TB


Proposal

When we are in the edit screen, we should disconnect the data field from the title, when the title is edited, we should not change the data field and user will need to change it manually.

girishpanchal30 commented 1 week ago

I've reviewed this ticket and fixed it here - https://github.com/Codeinwp/woocommerce-product-addon/pull/362

selul commented 1 week ago

@girishpanchal30 seems like you are making that readonly, I want to avoid those to sync when there is a value already saved, people can still change it if they want, but only if they change that field and not the title one.

girishpanchal30 commented 1 week ago

@selul I attempted to avoid syncing when saving data, but it isn't possible because data_name is stored in a serialized format within the_meta.

I also tried retrieving the existing the_meta and replacing the data_name, but this approach seems to cause an issue when reordering fields.

So I've just made it read-only and skipped the field update while editing the title.

selul commented 1 week ago

@girishpanchal30 I'm not sure if I get the issue, this looks like a frontend JS issue and has nothing to do with changing how we store the data or PHP side?

The logic is simple from my end, when editing an existing field, we can disable the js that changes the data name when I edit the title?

Am I missing something?

girishpanchal30 commented 1 week ago

'm not sure if I get the issue, this looks like a frontend JS issue and has nothing to do with changing how we store the data or PHP side?

On the PHP side, data is saved in a serialized format along with the POST data.

The logic is simple from my end, when editing an existing field, we can disable the js that changes the data name when I edit the title?

I've disabled it when the field is in read-only mode.

Here - https://github.com/Codeinwp/woocommerce-product-addon/pull/362/commits/b99a8628eb60a9c079cb107d3b4736a229996f0b#diff-44d139997568d1760113b5cad31792552415b4df27e795b0dfcbc21f36f4f024R994

selul commented 1 week ago

@girishpanchal30 instead of making it readonly, we can allow editing it when the user is directly editing that. RIght now there is no way to change that name, which he was able to do before.

girishpanchal30 commented 1 week ago

@selul I've removed the readonly attribute and disabled the auto data name update. Please check with the latest commit.

selul commented 1 week ago

@girishpanchal30 now when I add a new field, to an existing group, when writing the title the data is no longer being added automatically as before.

girishpanchal30 commented 1 week ago

@selul Fixed it with the latest commit.