Populating Default in Field Options - Select, Editor

Populating Default in Field Options - Select, Editor

TeonnynTeonnyn Posts: 10Questions: 1Answers: 0
edited October 2013 in Editor
How do I populate a Select dropdown with a Default option when I use "Edit"?
I don't expect "New" to have a default, but when I choose a row value on the table and
click edit, the Select dropdown doesn't pick it up - while the others get their proper values from the table.

Replies

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Can you link to the page showing the issue please? Likely the value doesn't === the values in the select list.

    Allan
  • TeonnynTeonnyn Posts: 10Questions: 1Answers: 0
    edited October 2013
    I'm afraid we couldn't and I partially solved for it, it's behind a VPN wall. However I've discovered an interesting new issue. Whenever I select one of the items in the dropdown, it only outputs the very first letter or number in the name/value - How can that be fixed?

    I'm also not quite sure how to structure our array for JSON to fit what DataTables expects. At the moment the structure is in a for loop and compiling this into the output:
    $aaData[] = [
    "Server" => $return[$i][Server], "Partner" => $return[$i][Partner], "Tag" => $return[$i][Tag], "Value" => $return[$i][Value]
    ];

    Output:
    [[{"Server":{"0":"-ALL-"},"Partner":{"0":"-ALL-"},"Tag":{"0":"IPAddress"},"Value":{"0":"jaworskiodev"}}

    I have a feeling fixing the array structure will fix the Select dropdown output as well.
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    DataTables can read just about any JSON format using mData: http://datatables.net/blog/Extended_data_source_options_with_DataTables (+ sAjaxDataProp ). The Editor select list however, expects to get value / label pairs of objects as used here: http://editor.datatables.net/release/DataTables/extras/Editor/examples/join.html

    Regards,
    Allan
  • TeonnynTeonnyn Posts: 10Questions: 1Answers: 0
    edited October 2013
    We got all that figured out! However...yet again another new bug has reared it's head. I'm now finally attaching everything to the forms and got "Edit" working. The form has two custom select fields and two regular fields. Clicking "New", however.... generates this log:
    Uncaught TypeError: Cannot read property 'type' of undefined

    The full code for the editor is here:
    [code]
    editor = new $.fn.dataTable.Editor( {
    "ajaxUrl": "index.php?getJSONAppConfigItems&code=<?php echo $this->items->UID[0]->Value ?>",
    "domTable": "#configitems",
    "events": {
    "onCreate": function (json, data) {

    },
    "onEdit": function (json, data) {
    $.ajax({
    type:"POST",
    cache:false,
    url:"index.php?editJSONAppConfigItems",
    data: { dataReturn: data, appUID: "<?php echo $this->items->UID[0]->Value ?>"},
    success: function (html)
    {
    tableInstance.fnReloadAjax();

    }
    });
    }
    },
    "fields": [ {
    "label": "Partner:",
    "name": "Partner",
    "type": "select",
    "ipOpts": [
    <?php

    foreach ($this->clientObjects->xpath('//*[local-name() = "row"]') as $object)
    {
    echo '{ "label": "'. $object['Name'].'", "value": "'. $object['UID'].'" },';
    }


    ?>
    { "label": "-ALL-", "value": "00000000-0000-0000-0000-000000000000" }
    ]
    }, {
    "label": "Server:",
    "name": "Server",
    "type": "select",
    "ipOpts": [
    <?php
    foreach ($this->serverObjects->xpath('//*[local-name() = "row"]') as $object)
    {
    echo '{"label": "'. $object['Name'].'", "value": "'. $object['UID'].'" },';
    }


    ?>
    { "label": "-ALL-", "value": "00000000-0000-0000-0000-000000000000" }
    ]
    }, {
    "label": "Tag:",
    "name": "Tag"
    }, {
    "label": "Value:",
    "name": "Value",
    }
    ]
    } );
    [/code]
  • TeonnynTeonnyn Posts: 10Questions: 1Answers: 0
    edited October 2013
    I think I figured it out. I need to apply a sDefaultContent, however, I'm not sure where or how this needs to be applied. Can anyone offer suggestions?

    EDIT: Okay, using sDefaultContent didn't help either... ugh!!! I really need that Select field to work when "new" is pressed.
  • TeonnynTeonnyn Posts: 10Questions: 1Answers: 0
    Okay.. I feel REALLY stupid. It was related to some enable/disable code. I finally figured it out by going through all of it step by step, checking my events, checking my fields, etc.
  • egberteegberte Posts: 13Questions: 1Answers: 0
    Editor has a default option:

    , {
    "type": "radio",
    "label": "Days:",
    "name": "days",
    "ipOpts": [
    { "label": "All", "value": "all" },
    { "label": "Selected:", "value": "selected" }
    ],
    "default": "all"
    }
This discussion has been closed.