editor field - setting the current value when using a dropdown list

editor field - setting the current value when using a dropdown list

craycray Posts: 10Questions: 0Answers: 0
edited November 2012 in Editor
I have a number of fields where I use the join to populate the dropdown for the selection. However, the editor always defaults to the first item in the list. I know I can set the field to a value using the API but I need to get the currently selected data first. I tried using editor.get(); but this function only returns the first element in the dropdown list. How is this accomplished? Otherwise everything else is working great. Thanks for your help.

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Just to be clear - you want to change the ordering got the items in the select list - is that correct? You'd need to know what the items in the list are, the value of the field (which you can get with `set` ) and use the `update` method for the field type with a bit of logic to reorder the select field. There isn't a built in method to reorder the items in the `select` control - it just displays them int he order that it is given in the data source array.

    Regards,
    Allan
  • craycray Posts: 10Questions: 0Answers: 0
    Allan, the problem is that I don't know how to get the current selected items. The editor displays the current selection for the items that are not dropdown lists but for the items that are dropdowns, the editor just displays the first item in the list, not the current item in the selected field. How do I find the real selected item in the field. Thanks.
  • JohnnyLJohnnyL Posts: 2Questions: 0Answers: 0
    edited November 2012
    Hi,

    I face the same issue I think....

    That is on the EDIT form the drop down fields do NOT pick up the current field VALUE, rather as stated above they just default to the first value of the dropdown...

    Just re read Allan's comment...Don't seem to understand the work around...?
  • JohnnyLJohnnyL Posts: 2Questions: 0Answers: 0
    edited November 2012
    Using the edit form I re selected the select field values and now they seem to work as in the demo...That is the edit form's select fields retain the current values...Not user why, maybe the way I imported the data....
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    I'm afraid I'm really confused. Could you link me to an example that illustrates the issue so I can see it in action?

    As you'll be able to see in this example ( http://editor.datatables.net/release/DataTables/extras/Editor/examples/fieldTypes.html ) if you create a row and then go back to edit it, the `select` field is set to the correct value. Is that what you are having issues with?

    Allan
  • craycray Posts: 10Questions: 0Answers: 0
    Hi Allan, if you take a look at the formOnlyData example, you'll notice that if you select Jessica and then edit, the dropdown list for Mr, Ms,... shows Mr., which is not the current value in the database. It seems that fields containing dropdown lists do not default to the current value but to only the first value in the dropdown list. This scenario is the same in my program. Therefore, any time someone edits a row, they'll have to reselect the current values for all of the dropdown lists, even though they may have only wanted to edit 1 item. Sorry for the confusion.
  • craycray Posts: 10Questions: 0Answers: 0
    Allan, I see now that the fieldTypes example works and I now see why the formOnlyData example doesn't (the data is not obtained from the database). I'll see if I can figure out why mine doesn't work properly. Thanks.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Hi,

    Good spotting with the formOnlyData example. The reason that isn't working is that the 'title' information isn't actually included in the JSON data that I had:

    [code]
    {
    "DT_RowId": "row_17",
    "first_name": "Jessica",
    "last_name": "Bryan",
    "phone": "1-949-932-6772",
    "city": "Boulder City",
    "zip": "F5P 6NU",
    "comments": "Nunc pulvinar arcu et pede. Nunc sed orci lobortis augue scelerisque mollis. Phasellus libero mauris, aliquam eu, accumsan sed, facilisis vitae,"
    },
    [/code]

    The server-side for that example didn't reference the title at all!

    Adding it in allows it to work correctly (which it now does).

    Allan
This discussion has been closed.