Okay
  Public Ticket #3800042
Adding Conditional Logic to Custom Fields in Amelia
Closed

Comments

  •  1
    Jannick started the conversation

    Hello Amelia Support Team,

    I am trying to implement conditional logic for custom fields within the Amelia booking form. Specifically, I would like to display or hide certain fields based on a user’s selection in another field (e.g., a dropdown or checkbox).

    For example:

    • If the user selects "Option A," Fields X and Y should appear.
    • If the user selects "Option B," Fields Z should appear instead.

    I am currently using the standard version of Amelia and couldn't find a built-in way to add this kind of dynamic functionality. I reviewed the documentation on custom fields and WP hooks (e.g., amelia_booking_custom_field_data), but I am unsure how to apply it in this context.

    Could you please let me know:

    1. Is it possible to implement conditional logic with the standard version of Amelia?
    2. If not, would the Pro version or additional custom code (e.g., JavaScript or hooks) be required?
    3. Could you provide a step-by-step guide or example code for setting up this logic?

    Thank you for your assistance. I look forward to your guidance.

    Best regards,

  •  1,633
    Uroš replied

    Hello Jannick,

    Thank you for reaching out.

    Conditional logic for custom fields is not natively available in Amelia, regardless of the version you're using. You will need to apply custom code to implement this functionality.

    Here’s what you need to do:

    1. Custom Code Required:
      • Whether you're using the standard or Pro version of Amelia, you will need to implement custom code (JavaScript or hooks) to achieve conditional logic for custom fields.
    2. Example Code: You can use JavaScript to show or hide fields based on user selection. Here's an example:
     
    jQuery(document).ready(function($) { // Initially hide all fields $('#fieldX, #fieldY, #fieldZ').hide(); // Show/hide fields based on dropdown selection $('#dropdownField').change(function() { var selectedOption = $(this).val(); if (selectedOption === 'Option A') { $('#fieldX, #fieldY').show(); $('#fieldZ').hide(); } else if (selectedOption === 'Option B') { $('#fieldZ').show(); $('#fieldX, #fieldY').hide(); } }); });

    This code listens for changes to a dropdown field (#dropdownField) and shows or hides certain fields (#fieldX, #fieldY, #fieldZ) based on the user’s choice.

    Feel free to reach out if you need further assistance with implementing this code or have any additional questions.

    Kind Regards, 

    Uros Jovanovic
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps, and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables