• Resolved darkside999

    (@darkside999)


    I have a radio button. Depending on its state, I need to hide fieldname45 (which is a DIV).

    I am currently using the “hide dependencies” function and it works visually, but the problem is that the values of the fields contained inside it are reset to zero. I still need those values for other calculations.

    How can I hide fieldname45 only visually?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author CodePeople2

    (@codepeople2)

    Hello @darkside999

    Dependencies do more than simply hide or show fields. When a field is configured as dependent, it is treated as empty in calculations while disabled, and it is also excluded from the form submission.

    If your goal is only to show or hide fields without disabling them, you should use a different approach. In this case, you can use the SHOWFIELD and HIDEFIELD operations.

    For example, suppose the radio button field is fieldname123, and you want to hide the div field fieldname45 when the radio button is unchecked, without disabling it.

    1. First, insert a calculated field in the form to act as an auxiliary field. Since this field is only used to control the behavior and should not appear in the form or be submitted to the server, enable the options in its settings to Hide the field from the public form, Exclude it from form submission (these are two checkboxes in the settings of the calculated fields).
    2. hen enter the following equation in its “Set equation” attribute:
    fieldname123 ? SHOWFIELD(fieldname45|n) : HIDEFIELD(fieldname45|n);

    Alternatively, you can use a function-style structure (both equations are equivalent):

    (function(){
    if(fieldname123) SHOWFIELD(fieldname45|n);
    else HIDEFIELD(fieldname45|n);
    })()

    Please note the equation uses the fieldname45 with the |n modifier (fieldname45|n), but not the fieldname123. The plugin automatically replaces field names in the equation with their current values before evaluating it. The |n modifier tells the plugin that you are referring to the field name itself, not its value.

    The equation can be read as: if the fieldname123 value is not empty (it is ticked), show the field whose name is fieldname45, if not, then hide it.

    Best regards.

    Thread Starter darkside999

    (@darkside999)

    PERFECT !!!!

    Thank you

    Plugin Author CodePeople2

    (@codepeople2)

    Hello @darkside999

    If you have been satisfied with both the plugin and our support, we would be immensely grateful if you could leave us a review on the plugin ( https://wordpress.org/support/plugin/calculated-fields-form/reviews/ ). Your feedback will help us reach more users. 

    Best regards. 

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

You must be logged in to reply to this topic.