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

Javascript error Invalid Char in LostFocus

6 Answers 63 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Malcolm
Top achievements
Rank 1
Malcolm asked on 08 May 2013, 04:09 PM
Dear KendoUI Team!
In one of my Views I alwas get a javascript error when I leave the focus of the Dropdownlist.

The error occurs in parseJSON in this line:
{return e.JSON&&e.JSON.parse?e.JSON.parse(n):null===n?n:"string"==typeof n&&(n=b.trim(n),n&&k.test(n.replace(S,"@").replace(A,"]").replace(E,"")))?Function("return "+n)():(b.error("Invalid JSON: "+n),t)}

The Model looks like this:
[Required]
        [LocalizedDisplayName("Language")]
        public int PreferredLanguageId { get; set; }

And the cshtml is here:

div class="type-text">                            
                            @(Html.Kendo().DropDownListFor(m => m.PreferredLanguageId)
                            .Name("PreferredLanguageId")
                            .SelectedIndex(Model.PreferredLanguageId)
                            .BindTo(LeoHelper.GetLanguages())
                            .DataTextField("Text")
                            .DataValueField("Value")
                            )
                        </div>

Although the javascript Exception is thrown, the value is correctly saved.

brgds
Malcolm Howlett

6 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 10 May 2013, 08:17 AM
Hi Malcolm,


From the provided information it's not clear for us what is the exact reason for this behavior - could you please provide runable project where the issue is reproduced? This would help us pinpoint the exact reason for this behavior.

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Christopher
Top achievements
Rank 1
answered on 06 Jun 2013, 10:32 AM
Hi, I have the same problem and I'm very interested to know how to fix this. I cannot provide a runable project but I can give you the following information:

Here's the JSON object I caught with firebug: [{"salesgeoid":5,"shortname":"ALL"},{"salesgeoid":1,"shortname":"BRA"},{"salesgeoid":3,"shortname":"CHE"},{"salesgeoid":2,"shortname":"FRA"}]

Here's my view:
<div class="editor-field">@(Html.Kendo().DropDownListFor(model => model.salesgeoid)
                                    .Name("salesgeo")
                                    .HtmlAttributes(new { style = "width:150px" })
                                    .DataTextField("shortname")
                                    .DataValueField("salesgeoid")
                                    .DataSource(source =>
                                    {
                                        source.Read(read =>
                                        {
                                            read.Action("SalesGeoList", "Profile");
                                        });
                                    }))</div>

And my controller:
public JsonResult SalesGeoList()
        {
            return Json(db.SalesGeo.Select(x => new { salesgeoid = x.salesgeoid, shortname = x.shortname }), JsonRequestBehavior.AllowGet);
        }
Your help would be greatly appreciated.
0
Vladimir Iliev
Telerik team
answered on 10 Jun 2013, 06:23 AM
Hi Christopher,

I reviewed the provided information, however currently  I'm unable to reproduce the issue on our side. I would suggest to try isolating the problem in a sample project and send it back to us. This would help us pinpoint the exact reason for this behavior. 

Also I would suggest to remove the Name configuration option as it overrides the name generated from the model property that is bound to the DropDownList. 

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Christopher
Top achievements
Rank 1
answered on 19 Jun 2013, 02:58 PM
It'll be hard to isolate the code since the data is stored in a mysql database.

However I followed your advice and I removed the name attribute, that helped me to access the data in the controller (it wasn't possible before). But the error message still appears in firebug. The message is : "SyntaxError: JSON.parse: unexpected character" and the file is "jquery.min.js (line 3)". Maybe this last information may help you find the source of this problem ?

Kind regards
0
Vladimir Iliev
Telerik team
answered on 20 Jun 2013, 06:25 AM
Hi Christopher,

 
Basically the data sent by the controller and the DropDownList configuration looks valid - most probably the issue is related to the scripts included in the project. I would suggest to check for duplicate script includes and make sure that all scripts are the correct versions (for example jQuery should be v1.9.1). For more information about the required scripts I would suggest to check this article

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Christopher
Top achievements
Rank 1
answered on 08 Jul 2013, 09:45 AM
Updating the scripts resolved the issue. Thank you for your help.
Tags
DropDownList
Asked by
Malcolm
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Christopher
Top achievements
Rank 1
Share this question
or