Add Default to Select options

Add Default to Select options

mankramomankramo Posts: 24Questions: 5Answers: 0

Hi everyone, please forgive me if this is a repeated question, i did searched through the forum but could not get a clear answer. Having said that, this is my question: I have a select field whose option is being populated by records from one of my tables in the db. when creating a new row, it automatically selects the first option and i don not want this to happen because the select field is optional so i want the first option to be have a null id and "select one" label. Also if an existing row is being edited i will want the null id and "select one " label to also be among the drop down options. I read on the forum that this can be done with a placeholder option but i just can't seem to understand how to structure it . this is my editor code -:

``var editor6 = new $.fn.dataTable.Editor( {
ajax: 'assets/datatable_assets/php/table.nestor_accountstructures.php',
table: '#nestor_accountstructures',
fields: [

    {
        "label": "Structure Name:",
        "name": "nestor_accountstructures.accountstructure_name"
    },
        {
        "label": "Segment 1:",
        "name": "nestor_accountstructures.accountstructure_segment1",
        "type": "select"
    }

....```

Please how do i add the placeholder to the above, thanks. @rf1234 :blush:

This question has accepted answers - jump to:

Answers

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406
    edited January 2018 Answer ✓
    {
        "label": "Structure Name:",
        "name": "nestor_accountstructures.accountstructure_name"
        attr: {
                    class: 'your class if you want to set one',
                    placeholder: "bla bla bla bla"
                }
    },
        {
        "label": "Segment 1:",
        "name": "nestor_accountstructures.accountstructure_segment1",
        "type": "select",
        placeholder: "bla bla bla"
    }
    

    https://editor.datatables.net/reference/field/select

    for select fields you can use "placeholder" directly, for other fields you would need to set an "attr" object as above

  • mankramomankramo Posts: 24Questions: 5Answers: 0
    edited January 2018

    Its working thanks @rf1234 . But the default option ['bla bla bla'] does not appear selection when editing a row

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406
    Answer ✓

    No, because it is a placeholder, not a default option. If you want the placeholder to be a default select option as well you would need to add it to the options that you use and put it on top of that list.

  • mankramomankramo Posts: 24Questions: 5Answers: 0

    Alright, thank you very much

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Editor's select field does actually have an option to be able to use the placeholder as a value - placeholderDisabled and placeholderValue are the two properties of interest there: select.

    Allan

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406

    Thanks @allan ! Good to know.

  • mankramomankramo Posts: 24Questions: 5Answers: 0

    Thanks gentlemen

This discussion has been closed.