Autocomplete in Editor with ID

Autocomplete in Editor with ID

greggreggreggreggreggreg Posts: 42Questions: 19Answers: 2

I want return a ID from the Editor Autocomplete field on Save, but show the text in search/select.

This works, but of course returns the text, not the ID:

  "label": "users_id:",
                "name": "usersname",
                "type": "autoComplete",
                "opts": {
                "source": ["abc","dsef","ebc"]
                    }
            },

This does not work, as it does not show me the drop down list:

  "label": "users_id:",
                "name": "users name",
                "type": "autoComplete",
                "opts": {
                "source": [{"id":1,"test":"abc"},{"id":2,"test":"dsef"},{"id":3,"test":"ebc"}]
                    }
            },

thanks

Answers

  • kthorngrenkthorngren Posts: 20,703Questions: 26Answers: 4,843
    edited March 2019

    Looks like your source object is not the correct format. According to the Autocomplete docs you will want to look at the jQuery autocomplete docs for the source object config. These docs state:

    An array of objects with label and value properties: [ { label: "Choice1", value: "value1" }, ... ]

    I think you will want to swap id/test with label/value.

    Kevin

  • greggreggreggreggreggreg Posts: 42Questions: 19Answers: 2

    Thanks Kevin, this is close. When I select my choice from the list, the value displays in the text field.

    i.e. I select a user, and in the text field I get the ID.

    Is that my only option for this? Its like its a Text box, but I guess I am learning I really want a select box?

  • allanallan Posts: 62,339Questions: 1Answers: 10,229 Site admin

    I want return a ID from the Editor Autocomplete field on Save

    Do you mean when you submit the whole form?

    What is the JSON being returned from the server on save? Does it contain both the id and the label?

    I'll confess I find the jQuery UI auto complete library quite hard to use - you frequently have to override its renderer to get it to display the way you want.

    Allan

This discussion has been closed.