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

Cascade Combobox problemo

1 Answer 76 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Radosław
Top achievements
Rank 1
Radosław asked on 06 Nov 2012, 11:11 AM
Hello.
Ive got two comboboxes:
-first one:
@(Html.Kendo().ComboBox()
    .Name("Dim1")
    .DataTextField("Barcode")
    .DataValueField("Barcode")
    .Filter(FilterType.StartsWith)
    .DataSource(action => action.Read(read => read.Action("GetStockLocationsForComboBoxAjax","StockLocation")).ServerFiltering(true))
    .MinLength(3)
    )
-second one:
<script type="text/javascript">
    function onAdditionalData() {
        return { Barcode: $("#Dim1").val() };
    }
</script>
 
@(Html.Kendo().ComboBox()
    .Name("Dim2")
    .DataTextField("Barcode")
    .DataValueField("Barcode")
    .Filter(FilterType.StartsWith)
    .DataSource(action => action.Read(read => read.Action("GetStockLocationsForComboBoxAjax","StockLocation").Data("onAdditionalData")).ServerFiltering(true))
    .MinLength(3)
    .CascadeFrom("Dim1")
    )
Here is my read action signature:
[HttpGet]
public JsonResult GetStockLocationsForComboBoxAjax([DataSourceRequest] DataSourceRequest request, string text, string Barcode)

When im putting some data in Dim1 ComboBox its sending it to controller with no problem, the child combobox (Dim2) becoming enable and everythings ok. But when Im starting to putting data in second combobox (Dim2) its sending only the parent data (Barcode from Dim1) and no Dim2 data:/ 
When im putting data in Dim2 I want to have Dim1 data under "Barcode" parameter and Dim2 data under "text" parameter.
What am I doing wrong?
Please help me!
I hope ive described it  enough clearly.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Radosław
Top achievements
Rank 1
answered on 08 Nov 2012, 11:00 AM
It turns out that when we override the default Data callback we have to take care of sending data from parent as well as the data from the current comboBox. So js function should look like this:
<script type="text/javascript">
    function onAdditionalData() {
         
        var Dim2 = $("#Dim2").data("kendoComboBox"),
        Dim1 = $("#Dim1").data("kendoComboBox"),
         
        value2 = Dim2.input.val(),
        value1 = Dim1.input.val();
         
        return {
            text: value2,
            Barcode: value1
        };
    }
</script>
Cheers!
Tags
ComboBox
Asked by
Radosław
Top achievements
Rank 1
Answers by
Radosław
Top achievements
Rank 1
Share this question
or