Multi-Select Field with choices callback and with a parent option
-
Hi,
Does anyone know how to create a multi-select field with choices callback and with a parent option in Ultimate Member?
I want to use the below code kindly given to me by MissVeronica, but my secondary field ‘function get_vehicle_types’ should be a multi-select.
function custom_vehicles_list_dropdown() { $vehicles = array( "Cars" => "Cars", "Vans" => "Vans", "Lorrys" => "Lorrys", "Aeroplanes" => "Aeroplanes", "Helicopters" => "Helicopters", ); return $vehicles; } function get_vehicle_types_dropdown( $has_parent = false ) { //get the value from the 'parent' field, sent via the AJAX post. //get the value from the 'parent' field, sent via the AJAX post. $parent_options = isset( $_POST['parent_option'] ) ? $_POST['parent_option'] : false; $vehicle_options = array( "Cars" => array ( "Hatchback" => "Hatchback", "SUV" => "SUV", "Saloon" => "Saloon", ), "Vans" => array ( "Box Van" => "Box Van", "City Van" => "City Van", "Crew Van" => "Crew Van", ), "Lorrys" => array ( "Lorry 1" => "Lorry 1", "Lorry 2" => "Lorry 2", ), "Aeroplanes" => array ( "Aeroplane 1" => "Aeroplane 1", "Aeroplane 2" => "Aeroplane 2", ), "Helicopters" => array ( "Compound" => "Compound", "Tandem Rotor" => "Tandem Rotor", ), ); $arr_options = array(); if ( ! is_array( $parent_options ) ) { $parent_options = array( $parent_options ); } foreach ( $parent_options as $parent_option ) { if ( isset( $vehicle_options[ $parent_option ] ) ) { $arr_options = array_merge( $arr_options, $vehicle_options[ $parent_option ] ); } elseif ( ! isset( $_POST['parent_option'] ) ) { foreach ( $vehicle_options as $k => $opts ) { $arr_options = array_merge( $opts, $arr_options ); } } } //code to do something if other options are not selected or empty match if ( empty( $arr_options ) ) { $arr_options[ ] = "no vehicles"; } else { $arr_options = array_unique( $arr_options ); } return $arr_options; }
Any help with this will be greatly appreciated.
Thank you,
Denis
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Multi-Select Field with choices callback and with a parent option’ is closed to new replies.