This is a migrated thread and some comments may be shown as answers.

Set selectedvalue combobox

2 Answers 519 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 17 Jan 2014, 03:57 PM
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 Answers, 1 is accepted

Sort by
0
Ramoji
Top achievements
Rank 1
answered on 18 Jan 2014, 10:19 AM
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
0
Tim
Top achievements
Rank 1
answered on 20 Jan 2014, 07:58 AM
Ramoji,

Thank you so much for your answer!

Tim
Tags
ComboBox
Asked by
Tim
Top achievements
Rank 1
Answers by
Ramoji
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Share this question
or