Title: Select dependent with multi-select
Last modified: November 10, 2024

---

# Select dependent with multi-select

 *  Resolved [c3media](https://wordpress.org/support/users/c3media/)
 * (@c3media)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/select-dependent-with-multi-select/)
 * Hello, i have implemented this codesnippet to create a dependent select and it
   works; however i would like to implement multi-select. Any idea yo solve it? 
   I tried but it disable the filter!
 *     ```wp-block-code
       // Filter to initialize the second select (lessons) as emptyadd_filter('fluentform/rendering_field_data_select', function ($data, $form) {    if ($form->id != 91) {        return $data;    }    // If it's the second select (lessons), we initialize it empty    if (\FluentForm\Framework\Helpers\ArrayHelper::get($data, 'attributes.name') == 'lesson_select') {        $data['settings']['advanced_options'] = []; // Initially empty the options    }    return $data;}, 10, 2);// AJAX handler to load lessons based on the selected courseadd_action('wp_ajax_update_lesson_select', 'update_lesson_select');add_action('wp_ajax_nopriv_update_lesson_select', 'update_lesson_select');function update_lesson_select() {    // Verify and get the course ID    $selected_course_id = intval($_POST['selected_course_id']);    if (!$selected_course_id) {        wp_send_json_error('Invalid course ID');    }    // Get the lessons that belong to the selected course    $lessons = get_posts([        'post_type'   => 'sfwd-lessons',        'meta_query'  => [            [                'key'     => 'course_id',  // Make sure this meta field exists and links lessons to courses                'value'   => $selected_course_id,                'compare' => '='            ]        ],        'numberposts' => -1    ]);    // Check if lessons were found    if (empty($lessons)) {        wp_send_json_error('No lessons found for the selected course');    }    $options = [];    foreach ($lessons as $lesson) {        $options[] = [            'label' => $lesson->post_title,            'value' => $lesson->ID        ];    }    // Send options as the AJAX response    wp_send_json_success($options);}// Add JavaScript to the footer to handle the change in the course selectadd_action('wp_footer', function() {    ?>    <script>    jQuery(document).ready(function($) {        // Change in the course select        $('select[name="course_select"]').on('change', function() {            var selectedCourseId = $(this).val();            // AJAX request to update the lesson select            $.ajax({                url: '<?php echo admin_url('admin-ajax.php'); ?>',                method: 'POST',                data: {                    action: 'update_lesson_select',                    selected_course_id: selectedCourseId                },                success: function(response) {                    var $lessonSelect = $('select[name="lesson_select"]');                    $lessonSelect.empty();                    if(response.success) {                        // Add options to the lesson select                        $.each(response.data, function(index, option) {                            $lessonSelect.append(new Option(option.label, option.value));                        });                    } else {                        alert('Error: ' + response.data);                    }                }            });        });    });    </script>    <?php});
       ```
   

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

 *  Plugin Support [Amimul Ihsan](https://wordpress.org/support/users/amimulihsanmahdi/)
 * (@amimulihsanmahdi)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/select-dependent-with-multi-select/#post-18126602)
 * Hello [@c3media](https://wordpress.org/support/users/c3media/),
 * Your code needs to be examined by our team, please share the details [here](https://wpmanageninja.com/support-tickets/)
   and if possible, please include a video recording of the process you have tried.
   Our team will assist you.
 * Thank you
 *  Thread Starter [c3media](https://wordpress.org/support/users/c3media/)
 * (@c3media)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/select-dependent-with-multi-select/#post-18129275)
 * Hi, This is a contribution to fluent forms; then the basic option (the above 
   code) is not officially available; i would like to get your support for this,
   implementing multi-select element.
 * My suggestion is to update your code and to implement **Smartcodes **([https://wpmanageninja.com/docs/fluent-form/miscellaneous/form-editor-smart-codes/](https://wpmanageninja.com/docs/fluent-form/miscellaneous/form-editor-smart-codes/))
   and **Dynamic fields** ([https://wpmanageninja.com/docs/fluent-form/field-types/dynamic-field-in-fluent-forms/](https://wpmanageninja.com/docs/fluent-form/field-types/dynamic-field-in-fluent-forms/)).
 * I believe it is high priority, i have a gravity forms license and will need this
   available to change to yours
 * Thanks
    -  This reply was modified 1 year, 6 months ago by [c3media](https://wordpress.org/support/users/c3media/).
      Reason: Clearity about my reply
 *  Plugin Support [Amimul Ihsan](https://wordpress.org/support/users/amimulihsanmahdi/)
 * (@amimulihsanmahdi)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/select-dependent-with-multi-select/#post-18131586)
 * Hello [@c3media](https://wordpress.org/support/users/c3media/),
 * Can you please share details on what needs to be changed on the documentation
   you have shared? We’ll check the details and get back to you.
 * Thank you
 *  Thread Starter [c3media](https://wordpress.org/support/users/c3media/)
 * (@c3media)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/select-dependent-with-multi-select/#post-18134030)
 * Based in selected course, get the lessons list
 * Chek image please: [https://drive.google.com/file/d/1x0Bx0W-Xvu7nNHrBWFSQJo9PTL1mcnw4/view?usp=sharing](https://drive.google.com/file/d/1x0Bx0W-Xvu7nNHrBWFSQJo9PTL1mcnw4/view?usp=sharing)
 * Thanks
 *  Plugin Support [Amimul Ihsan](https://wordpress.org/support/users/amimulihsanmahdi/)
 * (@amimulihsanmahdi)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/select-dependent-with-multi-select/#post-18142256)
 * Hello there,
 * It seems like you would like to populate a dynamic field based on the dropdown
   selection. Unfortunately, this is not possible by default.
 * Thank you

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

The topic ‘Select dependent with multi-select’ is closed to new replies.

 * ![](https://ps.w.org/fluentform/assets/icon-256x256.png?rev=3354580)
 * [Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder](https://wordpress.org/plugins/fluentform/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/fluentform/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/fluentform/)
 * [Active Topics](https://wordpress.org/support/plugin/fluentform/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/fluentform/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/fluentform/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Amimul Ihsan](https://wordpress.org/support/users/amimulihsanmahdi/)
 * Last activity: [1 year, 6 months ago](https://wordpress.org/support/topic/select-dependent-with-multi-select/#post-18142256)
 * Status: resolved