Jan 30, 2015, 7:30 PM
[CLOSED] combo remote validation has invalid json error
I have dynamic grid and a combo column needs remote direct validation. when combo is selected, the busy icon shows, but not seeing network call to the direct method and console has error:
Uncaught Ext.JSON.decode(): You're trying to decode an invalid JSON String: App.direct.ValidateCombo
3ext.axd?v=1895:18 Uncaught Ext.JSON.decode(): You're trying to decode an invalid JSON String: App.direct.ValidateComboext.axd?v=1895:18 Ext.Error.Ext.extend.statics.raiseext.axd?v=1895:1 8 Ext.JSON.me.decodeext.axd?v=1895:475 Ext.form.field.Base.override.remoteValidateext.axd ?v=1895:18 c
Not sure what I did wrong? I am using ext.net 2.5
Thanks
index.cshtml:
Uncaught Ext.JSON.decode(): You're trying to decode an invalid JSON String: App.direct.ValidateCombo
3ext.axd?v=1895:18 Uncaught Ext.JSON.decode(): You're trying to decode an invalid JSON String: App.direct.ValidateComboext.axd?v=1895:18 Ext.Error.Ext.extend.statics.raiseext.axd?v=1895:1 8 Ext.JSON.me.decodeext.axd?v=1895:475 Ext.form.field.Base.override.remoteValidateext.axd ?v=1895:18 c
Not sure what I did wrong? I am using ext.net 2.5
Thanks
index.cshtml:
@using Ext.Net;
@using Ext.Net.MVC;
@model EXTNETTEst30.ViewModels.GridViewModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Ext.NET MVC Sample</title>
<link type="text/css" rel="stylesheet" href="http://speed.ext.net/www/intro/css/main.css" />
</head>
<body>
@(Html.X().ResourceManager())
<header>
<a href="http://ext.net/"><img src="http://speed.ext.net/identity/extnet-logo-white-large.png" class="logo"/></a>
</header>
@(
Html.X().GridPanel()
.Frame(true)
.Height(800)
.Width(600)
.Store(
Html.X().Store()
.RemotePaging(false)
.PageSize(20)
.Proxy (
Html.X().AjaxProxy ()
.Url (Url.Action("LoadGridData", "ExtNet"))
.Reader(Html.X().JsonReader().Root("data").MessageProperty("message"))
)
.Model(Model.StoreModel) //define model data schema
.Parameters( new { gridId = Model.GridIDInt })
)
.ColumnModel(Model.Columns) //define display columns
.ColumnModel (
Html.X().CommandColumn()
.Width(70)
)
.View(
Html.X().GridView()
.StripeRows(true)
.LoadingText("Loading Grid Data...")
//.GetRowClass ( new Action<JFunction>("getRowClass"))
)
.Plugins(
Html.X().RowEditing()//.CellEditing().ClicksToEdit(1)
)
.Listeners(ls =>
{
ls.ValidateEdit.Fn = "validateEditor"; // this works
})
.TopBar(
Html.X().Toolbar()
.AutoScroll(true)
.Items(
Html.X().Button().ID("AddBtn")
.Text("Add")
// .Handler("onAddRow (this.up('grid'))")
)
)
)
<script>
Ext.create('Scripts.VTypes').init();
var validateEditor = function (editor, e) {
var column = e.column;
if (column != null) {
var valid = column.field.isValid();
if (!valid) {
e.cancel = true;
}
}
}
</script>
</body>
</html>
//ExtNetControl.cs:
using System;
using System.Web.Mvc;
using System.Collections.Generic;
using Ext.Net;
using Ext.Net.MVC;
using EXTNETTEst30.ViewModels;
using Newtonsoft.Json;
namespace EXTNETTEst30.Controllers
{
public class ExtNetController : Controller
{
public ActionResult Index()
{
// set view model with store schema definition and display column definitions
var vm = new GridViewModel();
vm.StoreModel = BuildStoreModel();
vm.Columns = BuildEditableColumn(vm.StoreModel.Fields);
return this.View(vm);
}
public Model BuildStoreModel()
{
Model storeModel = new Model();
storeModel.Fields.Add(new ModelField("Combo"));
return storeModel;
}
public IEnumerable<ColumnBase> BuildEditableColumn(ModelFieldCollection mfc)
{
ItemsCollection<ColumnBase> colCollection = new ItemsCollection<ColumnBase>();
Column col;
foreach (var mf in mfc)
{
col = new Column();
col.Text = mf.Name;
col.DataIndex = mf.Name;
ComboBox cob = new ComboBox();
cob.AllowBlank = false;
cob.QueryMode = DataLoadMode.Local;
cob.ForceSelection = true;
cob.DisplayField = "Text";
cob.ValueField = "Value";
cob.EmptyText = "Select a One...";
cob.IsRemoteValidation = true;
cob.RemoteValidation.DirectFn = "App.direct.ValidateCombo";
cob.RemoteValidation.ErrorMessage = "Wrong item!";
//cob.RemoteValidation.Validation += ValidateCombo; //.Url = Url.Action("ValidateCombo", "ExtNet");
//cob.RemoteValidation.ValidationEvent = "select";
//cob.RemoteValidation.EventOwner = ValidationEventOwner.Field;
var proxy = new AjaxProxy();
proxy.Url = Url.Action("LoadCombo", "ExtNet");
proxy.Reader.Add(new Ext.Net.JsonReader { Root = "data" });
var model = new Model { IDProperty = "Value" };
model.Proxy.Add(proxy);
model.Fields.Add(new ModelField { Name = "Text" });
model.Fields.Add(new ModelField { Name = "Value" });
var store = new Store { AutoLoad = true };
store.Model.Add(model);
cob.Store.Add(store);
cob.TypeAhead = true;
col.Editor.Add(cob);
colCollection.Add(col);
}
return colCollection;
}
[DirectMethod]
public object ValidateCombo(string value) //(object sender, RemoteValidationEventArgs e)
{
if (value == "Item2")
return true;
return "Item2 is valid value only";
}
public ActionResult LoadGridData(string action, Dictionary<string, object> extraParams, int gridId)
{
var l = new List<Dictionary<string, object>>();
var row = new Dictionary<string, Object>();
row.Add("Combo", "Item1");
l.Add(row);
return this.Store(l);
}
public ActionResult LoadCombo()
{
var results = new List<NewListItem>();
results.Add(new NewListItem { Text = "Item1", Value = "Item1" });
results.Add(new NewListItem { Text = "Item2", Value = "Item2" });
return this.Store(results);
}
}
}
GridViewModel.cs:
public class GridViewModel
{
public Model StoreModel { get; set; }
public IEnumerable<ColumnBase> Columns { get; set; }
}
Last edited by fabricio.murta; Feb 06, 2015 at 10:18 PM.
Reason: [CLOSED]