how to set the selected attribute of an option of a select list?

how to set the selected attribute of an option of a select list?

tharvey2tharvey2 Posts: 4Questions: 2Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Answers

  • tharvey2tharvey2 Posts: 4Questions: 2Answers: 0

    oops, hit enter too quickly.
    referring to this other question: https://datatables.net/forums/discussion/19579

    If I want some of the months to be selected, I find that the following attempts do not work:
    "ipOpts": [
    { "label": "January", "value": "jan", attr: {selected:true}},
    { "label": "February", "value": "feb" , selected:true },
    { "label": "March", "value": "mar" , "selected":"true" },
    { "label": "April", "value": "aprl" , "checked":"1" },
    { "label": "May", "value": "may" },
    { "label": "June", "value": "jun" },
    { "label": "July", "value": "jul" },
    { "label": "August", "value": "aug" },
    { "label": "September", "value": "sept" },
    { "label": "October", "value": "oct" },
    { "label": "November", "value": "nov" },
    { "label": "December", "value": "dec" }
    ]

    What is the syntax to cause an option to render as "selected" when the select list is dropped?

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    Start with this SO thread. There are others that show ways of doing this. If you still need help then create a simple test case showing what you have and what you want to do so we can offer suggestions.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • tharvey2tharvey2 Posts: 4Questions: 2Answers: 0

    so, to confirm, there is no attribute "selected" on the particular items in ipOpts and it requires jquery or other code to achieve this in the DataTables/Editor form.

    To clarify my original question, is there an attribute of the ipOpts items that caused that item to be selected when the SelectList is rendered.

    If the original question, I want January, February, March, and April all to be rendered as selected, and I want to do it with the ipOpts data alone.

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    You are correct - there is no selected parameter for the options of a select input. The selected value will either come from the row being edited or the field's default value (field.def). For that reason a selected parameter would never actually get used!

    If you want some values to be preselected on create, do so with the field default.

    Allan

Sign In or Register to comment.