Remove content of hidden fields

  • Posts: 53
  • Thank you received: 3
  • Hikashop Business
3 months 2 weeks ago #363001

-- url of the page with the problem -- : shangshungpublications.com/
-- HikaShop version -- : 5.1.0
-- Joomla version -- : 5.1.4
-- PHP version -- : 8.2

Hi,
I've made conditional fields, ie. "vat" field shown only if the customer type is set to "company" with a radio button. If the customer set the "vat" field then he decide to change the "company" field to "private", the "vat" field, correctly, becomes hidden but its value remains. Is it possible to delete automatically the value of hidden fields?
Thank you

Last edit: 2 weeks 6 days ago by nico1979.

Please Log in or Create an account to join the conversation.

  • Posts: 83022
  • Thank you received: 13403
  • MODERATOR
3 months 2 weeks ago #363004

Hi,

Do you mean that you want the value to be removed from the input on the fly in javascript because you have some custom javascript that reads this value and it needs to reflect the state of the parent field ?
Or do you mean that the value previously entered in the input is stored in the database and you don't want that to happen ?
While the first is a bit difficult, the second should already be the case without doing anything.

Supposing that you're talking about the first, the problem is that each field type can have different ways to store what the user provides. So the javascript needs to adapt to that. However, since the javascript of the custom field system doesn't know how the HTML of the type handles itself, it means that we would need to build a system where each custom field would add its own javascript to be triggered to empty itself. It's a lot of work for something which should be manageable easily in your own javascript if you're already have your own custom javascript code. Or maybe I'm missing something on what you're trying to do ?

Please Log in or Create an account to join the conversation.

  • Posts: 53
  • Thank you received: 3
  • Hikashop Business
1 month 1 week ago #364459

Hi,
At the moment if a user accidentally fills in the company name (which is a hidden field visible only if you choose to be a company and not a private individual) the company name value remains even when you switch to private. We would like that in this case the hidden values ​​(even if accidentally filled in) do not remain when saving the form.
Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 83022
  • Thank you received: 13403
  • MODERATOR
1 month 1 week ago #364466

Hi,

Mmm. I'm still not clear on your issue.

Suppose this scenario:
- I access the new address form
- in the address form I select "company"
- the company name input field appears
- I fill in that field
- I continue filling other fields on that form
- now, before saving the new address, I realize that I want to select "individual"
- I select "individual"
- the company name input filed disappears
- I click on the "save" button
The address is saved in the database without anything in the company field.
This scenario fits with everything you've said so far here as far as I understood, and as I said previously, this is already working. I made sure it is by reproducing this scenario on my end.
If this is not working as expected on your end, then there is a bug I'm not able to reproduce on my end with the latest version of HikaShop. That would be something we would need to investigate on your website.

Now, while analyzing what you said and trying to reproduce the issue on my end, I found out that this other scenario could be improved:
- I access the new address form
- in the address form I select "company"
- the company name input field appears
- I fill in that field
- I continue filling other fields on that form
- I save the address
- now, after saving the new address, I realize that I want to select "individual"
- I edit the address
- I select "individual"
- the company name input filed disappears
- I click on the "save" button
In that case, the previously saved company name is still in the database. And I think that ideally, it should not.
Changing this is actually quite easy.
Change the code:

						if(isset($formData[$namekey]))
							unset($formData[$namekey]);
						$skip = true;
to:
						$formData[$namekey] = '';
						$skip = true;
in the file administrator/components/com_hikashop/classes/field.php via FTP. Then, in this second scenario, the company name is removed from the database during the second save.
I think we're going to add this modification on our end for the next version of HikaShop. If this is what you were talking about, then, do this patch or wait for the next version of HikaShop and you'll get it to work like you want.

Please Log in or Create an account to join the conversation.

  • Posts: 53
  • Thank you received: 3
  • Hikashop Business
1 month 1 day ago #364581

Thank you, now it works perfectly.

Please Log in or Create an account to join the conversation.

Time to create page: 0.062 seconds
Powered by Kunena Forum