ArtiGrid
v1.5

Dropdowns Dependent

This example demonstrates how to create dependent dropdowns using ArtiGrid. The second dropdown (manager) dynamically updates its options based on the selected value of the first dropdown (office).

When a user selects an office, the system automatically filters and loads only the employees that belong to that office. This allows for more accurate data selection and improves the user experience by preventing invalid combinations.


<?php
    $grid = new ArtiGrid();
    $grid->table('consultation')
        ->template('bootstrap5')
        ->required(false)
        ->validation_required([
            'office',
            'manager',
            'country',
            'region',
            'city'
        ])
        ->fields_arrange('office,manager,name', 'Group 1 - Names', true, true)
        ->fields_arrange('country,region,city', 'Group 2 - Regions', true, true)
        ->combobox('office','offices','officeCode','city')
        /*->combobox('office','offices','officeCode','city', null, null, ['country' => 'USA'])*/
        ->combobox('name', [
            'Pedro' => 'Pedro',
            'Juan' => 'Juan',
            'JHON' => 'JHON',
            'JACKSON' => 'JACKSON' 
        ])
        ->combobox(
            'manager',
            'employees',
            'employeeNumber',
            ['firstName','lastName'],   // label
            'office',      // name of the parent field in the form
            'officeCode'   // column in the database
        )
        ->combobox('country','meta_location','id','local_name', null, null, ['type' => ['=', 'CO']])
        ->combobox('region','meta_location','id','local_name','country', 'in_location', ['type'=> ['=', 'RE']])
        ->combobox('city','meta_location','id','local_name', 'region', 'in_location', ['type'=> ['=', 'CI']]);

    echo $grid->render('insert');
?>
Group 1 - Names
Group 2 - Regions