Select Box Options - Allow extra field of NULL

Select Box Options - Allow extra field of NULL

mRendermRender Posts: 151Questions: 26Answers: 13

Right now with my current set up I have:

Field::inst( 'tbl_Controller.MID' )
            ->options( 'tbl_Models', 'MID', 'model_no' ),

{
                label: "Model:",
                name: "tbl_Controller.MID",
                type: "select"
            },

Everything works great with this.

But what if, at the time of creating or editing, I don't want a value in this field.

I would almost want something like this:

Field::inst( 'tbl_Controller.MID' )
->options( '', '(NULL)', '' ),
->options( 'tbl_Models', 'MID', 'model_no' ),

Any additions I've tried to make to this field results in ->options( 'tbl_Models', 'MID', 'model_no' ), being in the select box list.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    The Field->options() method when passed three strings, as documented, will make a request to the database based on the parameters given. If you want to add an option you have two options:

    1. Modify the data to be returned to the client - which you can get using the Editor->data() method and then do something like $data['options']['tbl_Controller.MID'][] = array( ... );.
    2. Use Field->options() with a closure function where you defined what data will be shown in the list.

    Allan

This discussion has been closed.