Set selectedvalue combobox

3 posts, 1 answers
  1. Answer
    Tim
    Tim avatar
    13 posts
    Member since:
    Dec 2013

    Posted 17 Jan 2014 Link to this post

    I'm using a combobox to create a searchable list of employees from where the user needs to select one.
    If there is a false name entered they should get a warning (which already works) and the first person in the list needs to be selected. I Was trying to do that like this:

    <div class="editor-field edit-project">
    (Html.Kendo().ComboBox()
    .Name("PersonId")
    .HtmlAttributes(new { @class = "input-project" })
    .DataTextField("Fullname").DataValueField("Id")
    .DataSource(source => { source.Read(read => { read.Action("GetPeople", "Project"); }); })
    .MinLength(3)
    .Filter("contains")
    .Events(ev => ev.Change("checkcombobox")))
    </div>
    And in javascript i'm doing this:

    function checkcombobox(e)
    {
        if (this.value() && this.selectedIndex == -1) {
            alert('Gelieve een geldige persoon te selecteren');
            var cbx = $("#PersonId").data("kendoComboBox").Selected(0);
     
        }
    }
    Could anyone help?

    Thanks in advance
  2. Ramoji
    Ramoji avatar
    3 posts
    Member since:
    Nov 2012

    Posted 18 Jan 2014 Link to this post

    Tim,

    Try this code . It worked for me.

    function onComboChanged(e)
    {
        if (this.value() && this.selectedIndex == -1) {
            this._filterSource({
                value: "",
                field: this.options.dataTextField,
                operator: "contains"
            });
            this.select(1);
        }
    }
    Thanks,
    Ramoji
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Tim
    Tim avatar
    13 posts
    Member since:
    Dec 2013

    Posted 20 Jan 2014 Link to this post

    Ramoji,

    Thank you so much for your answer!

    Tim
Back to Top