• Hello,
    is there any (UI-based) way to set up lists of values that you can refer to when setting up rules.

    E.g.: Show field “income” only if value of field “employment status” is in list “relevant employent status” (which includes values like “employee” or “self-employed”)

    Besides easier rule-setup it would help to maintain the rules if the relevant values change.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hello @infocade

    Hope you’re doing well today! Thank you for reaching out to us.

    From what I understood, you are looking to manage all visibility conditions for a form (all fields) at a single location as a list. Am I understanding it right?

    Currently, the visibility rules can be applied only via specific fields. Ref: https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#Forminator-Conditional-Logic

    To explain further, based on the example you shared

    You will need to add a visibility condition on the income field to show – only when the “employment status” field has a specific value selected/typed, for example “Self-Employed”

    Here is an example of how the condition would look like on the income field: https://monosnap.com/file/DjrWlz9VZF5328o610D55qTaiw44hH

    Please let us know if this helps.

    Kind Regards,
    Saurabh

    Thread Starter infocade

    (@infocade)

    Thanks for the swift reply here as well, Saurabh @wpmudev-support7 !
    The challenge is to have an “allow-list” of values. I understand that this is currently not possible.

    Is there any work-around then?
    My idea would be a binary hidden field. If the user picks a value from the “allow-list” in a select-field this hidden field has value 1. Else, its value is 0.
    In this case set-up and maintenance has to address the visibily-rules of this hidden-field only instead of every field that refers to this “allow-list”.
    But this doesn’t seem to be easy either!?

    Note that my example above (employment-status + income) might be a bit misleading. I’m talking about long lists of options that might be amended/reduced over time, while also the “allow-list”-status of single options might change.

    Thread Starter infocade

    (@infocade)

    Solved with this JQUERY-script (adjusted – syntax should be validated before use)

    jQuery(document).ready(function ($) {
    $(document).on('select2:select change', 'select[name="select-1"]', function () {
    let selectedValue = $(this).val();
    let allowedValues = ["allowedvalue1", "
    allowedvalue2", "allowedvalue3"];
    let hiddenField = $('input[name="hidden-5"]');
    if (allowedValues.includes(selectedValue)) {
    hiddenField.val("1");
    } else {
    hiddenField.val("0");
    }
    });
    });

    Edit: Formatting is off – can’t help it quickly. Sorry!

    • This reply was modified 4 days, 10 hours ago by infocade.
    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @infocade,

    Solved with this JQUERY-script (adjusted – syntax should be validated before use)

    Sounds like you have managed to figure it out.

    I’m afraid at the moment other than the default conditions, it’ll require custom coding to change the current behaviour.

    Kind Regards,

    Nithin

    Thread Starter infocade

    (@infocade)

    Hi Nithin @wpmudev-support7 ,

    Sounds like you have managed to figure it out.

    Turned out we haven’t ??
    I managed to populate the binary hidden field and also I can show/hide other fields based on the value of this binary field. So frontend-wise everything works well.
    HOWEVER: Apparently, fields that are shown based on the value of this binary hidden field are not submitted properly in the end. When I switch back to showing them based on the particular values of the select-field (instead of the allow-list workaround) everything works well again.
    Would you know why this happens?

    If it wouldn’t work at all I would need to rework the whole thing ofc. But that it’s working half the way seems weird to me.

    • This reply was modified 3 days, 7 hours ago by infocade.
    • This reply was modified 3 days, 7 hours ago by infocade.
    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @infocade,

    This is more likely due to the form options not being synchronized between the front end and backend.

    Trying to fill fields with JS can cause errors during submission because the field doesn’t have the same option available on the backend.

    To resolve this, you’ll need to fill in the form’s options on the backend as well. The Forminator API provides a method to update form field options programmatically, which can help you achieve this.

    A general approach you can follow is to utilize the update_form_field() method to update field options in the backend. This ensures that the field options are correctly recognized by the form’s validation system, then Identify the form and field IDs and generates dynamic options to update the form field.

    You can refer to this doc for more info:
    https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/#method-update_form_field

    However, I’m afraid providing the exact code will be outside the scope of support. For that, you’ll need to hire a developer to provide the required custom code for you. WordPress provides a jobs directory here?https://jobs.wordpress.net/

    If you need further advice about it, feel free to email us at [email protected] using the following subject.

    “Subject: ATTN: WPMU DEV support – wp.org”

    Regards,

    Nithin

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.