editor dependend with NULL option

editor dependend with NULL option

koniahinkoniahin Posts: 186Questions: 39Answers: 7

I got editor dependent working nicely with a list of country and region codes. I now realize that we don't always have the region name to select from the list. In that case we need to add a NULL or empty --select-- option as the first item in the select list. How do we do that?

    $regions = $db
        ->select( 'regions', ['regions.region_code as value', 'regions.region_name as label'], ['regions.country_code' => $_REQUEST['values']['roster.pob_country_code'], 'publish' => 'Yes'] )
        ->fetchAll();

    echo json_encode( [
        'options' => [
            'roster.pob_region_code' => $regions
        ]
    ] );

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Rather than doing it on the server-side, it is easiest to to it on the client-side with the options that select makes available. Specifically the:

    • placeholder
    • placeholderDisabled
    • placeholderValue

    properties will be the ones of interest to you.

    You'll likely also need a set formatter to convert the empty string submitted by the HTTP variables to be a null value. See the docs for that here.

    Allan

Sign In or Register to comment.