Default value from select dropdown

Default value from select dropdown

gbenettgbenett Posts: 14Questions: 5Answers: 0

In Editor, I'm not sure why the following field doesn't submit "TBD" as a placeholder when the user submits (create or edit) without selecting an option. Everything else is working; I just want a default value when the required data is currently unknown.

fields: [..., {
                        label: "Db Name:",
                        name: "CurrentDbName",
                        type: "select",
                        placeholder: "Select from DBs on Host:",
                        placeholderDisabled: false,
                        placeholderValue: "TBD"
          },
]

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    What version of Editor are you using? Can you five me a link to the page showing the error so I can debug it?

    Thanks,
    Allan

  • gbenettgbenett Posts: 14Questions: 5Answers: 0
    edited November 2016

    Using Editor 1.5.6 (latest). Can't readily simulate the app outside our firewall -- maybe this is enough? Debug info at http://debug.datatables.net/atodox

    The relevant table is #mainTable; relevant row code begins around line 407:

                                    "name": "GuardiumInventory1.HostName",
                                    "classes": "-- Previously seen object. Not included due to circular reference possibility --",
                                    "host": "-- Previously seen object. Not included due to circular reference possibility --",
                                    "opts": {
                                        "className": "",
                                        "data": "GuardiumInventory1.HostName",
                                        "def": "",
                                        "fieldInfo": "",
                                        "id": "DTE_Field_GuardiumInventory1.HostName",
                                        "label": "HostName*:",
                                        "labelInfo": "",
                                        "name": "GuardiumInventory1.HostName",
                                        "type": "select2",
                                        "opts": {
                                            "placeholder": "Select a Host",
                                            "tags": false,
                                            "minimumInputLength": 2,
                                            "ajax": {
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Embarrassingly, that's a bug in Editor 1.5.6 I'm afraid! It is just completely ignoring the placeholder value because of how the value is read from the select element (Editor stores the value on a property of the element to allow for strict type checking).

    To patch a local copy against this issue open dataTables.editor.js in your Editor and find:

                elOpts[0].hidden = disabled; // can't be hidden if not disabled!
                elOpts[0].disabled = disabled;
    

    Immediately after those two lines add:

    elOpts[0]._editor_val = conf.placeholderValue !== undefined ?
        conf.placeholderValue :
    '';
    

    I'll have that fix in the next release! Thanks very much for letting me know about this and my apologies for the issue.

    Regards,
    Allan

  • gbenettgbenett Posts: 14Questions: 5Answers: 0

    Great answer, as usual. :) Works like a charm.

This discussion has been closed.