Menu

#91 Filtering the $Select_options in a custom field depending of other field value

open
nobody
None
1
2019-10-06
2019-10-04
No

Hi!, I want to filter to $Selec_options of a custom field according the value of another custom field (also with $select_options).
The same way as Area and it's rooms does.
¿Any idea how can I do it?.
Thank you.

Discussion

  • Campbell Morrison

    You're going to have to do it in JavaScript, so that when one custom field changes, so do the options for the other.

     
  • Juan Pablo Beltramone

    Yes, I Imagine that, but I'cant find where (in what part of code) do it.

     
  • Juan Pablo Beltramone

    I can see there is file: 'edit_entry.js.php', ¿Is that te correct place?

    Any example of how to do it ?
    Thank you very much.

     
  • Campbell Morrison

    Yes, you'll have to modify edit_entry.php and edit_entry.js.php.

    As you say, the way it is done for areas and rooms is an example. What you'll need to do in edit_entry.php is create a select element for each of the possible values of the other custom field, and then set the CSS display attribute to none for all but the currently selected one. Then in the JavaScript file you'll need to set up a .change listener so that when your other custom field changes then it shows the element corresponding to the new value and hides the element corresponding to the old one.

     
    • Juan Pablo Beltramone

      I see this part of code that seems to do it, but I can't understand it.

            <?php // Switch room selects ?>
            var roomSelect = $('#rooms');
            roomSelect.html($('#rooms' + newArea).html());
      

      That's beyond my knowledge. Thanks anyway Campbell.

       

      Last edit: Campbell Morrison 2019-10-06
  • Campbell Morrison

    Ah, yes, I'd forgotten. The rooms are changed not by hiding and showing the relevant select elements, but by replascing the HTML of the main select element with the HTML for the select element corresponding to the selected area. See https://api.jquery.com/html/.