• Resolved dharrisonweb

    (@dharrisonweb)


    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.

    • This topic was modified 7 years, 6 months ago by dharrisonweb.
    • This topic was modified 7 years, 6 months ago by dharrisonweb.
Viewing 3 replies - 1 through 3 (of 3 total)
  • I tried to install this in header (and later footer, but no difference), and I can’t get it to work… it won’t clear the fields. Do you have any ideas on how to solve it?

    Thread Starter dharrisonweb

    (@dharrisonweb)

    Hi,

    I should have mentioned:

    The first snippet is taken from lines 215 to 221 in the scripts.js file, located in the /js/ folder in the plugin, the second snippet is to replace those lines to stop the values being stripped from checkboxes and radio buttons.

    Does that make more sense?

    I was hoping the plugin creator would have a look at this and add it to the plugin if they felt it was right.

    Plugin Author Jules Colle

    (@jules-colle)

    I’m afraid there is some misunderstanding about the clear on hide option. The clear on hide option should never be checked except for some edge cases.

    By default the form will not cause any validation errors on fields that are in hidden groups, and with the conditional tags in teh e-mail you can always include only the groups that were visible during submission. The clear on hide is only useful if, for some reason, you don’t want the data to be cleared if a user changes their mind. So, just uncheck the clear on hide box and everything should work the way you want it to.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Clear on hide bug possible fix’ is closed to new replies.