Clear on hide bug possible fix
-
Hi,
I’ll start by saying I really like this plugin, it gives CF7 a feature that I’ve used a lot in expensive paid-for plugins and does it well so thanks for releasing it!
However, I’ve noticed a bug with the clear on hide function which was causing an issue on the form I was testing your plugin on.
So when a field group gets hidden the fields get cleared, which is what I want to happen, but if the user then changes their mind and their selection shows those fields again, any checkboxes and radio buttons have lost their value so they would come through as blank even if they were selected.
I’ve had a look at the code and I think I’ve found a solution. In this block where you clear the values and remove the checked/selected property, it’s clearing all values but really I think you should exclude radio and checkboxes from this. So currently you have this:
if ($group.attr('data-clear_on_hide') !== undefined) { $(':input', $group) .not(':button, :submit, :reset, :hidden') .val('') .prop('checked', false) .prop('selected', false); }For radio buttons and checkboxes you only need them to be unchecked, the values would remain, so I’ve changed it to this:
if ($group.attr('data-clear_on_hide') !== undefined) { $(':input', $group) .not(':button, :submit, :reset, :hidden') .prop('checked', false) .prop('selected', false) .not(':radio, :checkbox') .val(''); }This seems to be working, it’s clearing any values from the other fields (text inputs, dropdowns etc) but the checkboxes and radio values remain but are unchecked.
Let me know if this is right or if you find a better way to solve this.
The topic ‘Clear on hide bug possible fix’ is closed to new replies.