Set object as DataItem programatically

2 posts, 0 answers
  1. Software
    Software avatar
    1 posts
    Member since:
    Jul 2018

    Posted 06 Aug Link to this post

    I use AutoComplete as people picker

    When selecting element, the whole object is selected (but just first name and last name is shown).

    You can get selected object by: $("#" + controlId).data("kendoAutoComplete").dataItem()

    The problem is when I fill the form with data. I don't know how to set object to autocomplete so there would be value in "dataItem"

    $("#" + controlId).data("kendoAutoComplete").value("test") is setting only what's displayed

    I need this to validate whether the proper element was selected and I need all of the other properties of the the object.

     

    How to set object as selected element in AutoComplete

     

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1599 posts

    Posted 07 Aug Link to this post

    Hi,

    Unlike the DropDownList or the ComboBox the AutoComplete does not have a dataValueField. Only the field set as dataTextField is used to set the value and only the widget's text is sent to the server on form submission. A workaround you could consider using is to access the selected item's dataItem in the AutoComplete's select event handler. Get the field value you need from the dataItem and save it in a hidden field. On form submission get the field value from the hidden field.

    Regards,
    Ivan Danchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top