[OPEN] [#183] Data annotations appear to break store batch update mechanisms

  1. #1

    [OPEN] [#183] Data annotations appear to break store batch update mechanisms

    I am attempting to dynamically add records to a store and then synchronize the store with an ASP.NET MVC 4 server. I can add records to the store; however, the store will not acknowledge the records in the getChangedDatamethod or an invocation of the sync method. It appears to detect deleted or changed records. I have isolated the problem and noted it occurs when you include a StringLength data annotation attribute on a string property in the model.

    Environment
    • Visual Studio 2012
    • ASP.NET MVC 4
    • Ext.NET SVN r4964


    Steps to Reproduce
    1. Execute the provided sample
    2. Modify a record in the grid panel or add a record with the add button
    3. Press the save button
    4. Observe the console


    Comments

    If you look at the client-side javascript, the data annotation adds validation information to the store's model (this is expected); however, this appears to prevent the store from properly reporting created or changed records. The side effect is methods such as sync and getChangedData do not work properly.

    If you remove the StringLength data annotation, the store will properly report created or changed records again.

    Model
        [Model(Name = "TestModel", ClientIdProperty = "PhantomId")]
        public class TestModel
        {
    
            [ModelField(IDProperty = true, UseNull = true)]
            public int ID { get; set; }
    
            [ModelField(Ignore = true)]
            public string PhantomId { get; set; }
    
            [StringLength(32)]
            public string Name { get; set; }
    
            public TestModel(string name)
            {
                this.Name = name ?? String.Empty;
            }
    
        }
    View
      @(Html.X().GridPanel()
            .ID("TestGrid")
            .TopBar(Html.X().Toolbar()
                .Items(
                    
                    Html.X().Button()
                        .Text("Add")
                        .OnClientClick("Test.onAdd()"),
                        
                Html.X().Button()
                    .Text("Save")
                    .OnClientClick("Test.onSave()")
                    
                )
            )
            .Store(Html.X().StoreFor(typeof(TestModel))
                .Proxy(Html.X().AjaxProxy()
                    .Url(Url.Action("Retrieve"))
                    .ActionMethods(m => m.Read = HttpMethod.POST)
                    .Reader(Html.X().JsonReader()
                        .Root("Data")
                    )
                )
            )
            .ColumnModel(
                Html.X().Column().Text("Name").DataIndex("Name")
                    .Editor(Html.X().TextField())
            )
            .Plugins(Html.X().CellEditing())
        )
    Script
    var Test = {
    
        onAdd: function() {
    
            var grid = Ext.getCmp('TestGrid');
            var store = grid.store;
    
            var record = store.model.create();
            
            store.add(record);
    
        },
    
        onSave: function () {
            
            var grid = Ext.getCmp('TestGrid');
            var store = grid.store;
    
            var data = store.getChangedData(
                    { skipIdForPhantomRecords: false });
    
            console.log(data);
    
        }
    
    };
    Controller
        public class TestController : Controller
        {
            public static List<TestModel> Models = new List<TestModel>();
    
            static TestController() {
                for (int i = 0; i < 5; i++)
                    Models.Add(new TestModel(String.Format("Record {0}", i + 1)));
            }
    
            public ActionResult Index()
            {
                return View();
            }
    
            [HttpPost]
            public ActionResult Retrieve()
            {
                return this.Json(Models);
            }
    
        }
    Last edited by Daniil; Apr 02, 2013 at 2:15 PM. Reason: [OPEN] [#183]
  2. #2
    Hello!

    This happens due to your new record is not Valid because the model's field minimum length is 32. To get all records including invalid you should the following code:

    var data = store.data.filterBy(store.filterNewOnly).items;
    Last edited by Baidaly; Apr 01, 2013 at 10:04 PM.
  3. #3
    Hello,

    I think it is the destination of validation - it should prevent submitting invalid data to server.

    If you want to submit invalid data, please clarify why do you use validation, i.e. the StringLength attribute?
  4. #4
    Please forget my last post.

    I think we have found the problem. The length validation returns false for undefined or null.

    We think it is wrong if there is a max boundary only.

    We will fix it soon in SVN. For now please use the following fix.

    Fix
    Ext.data.validations.length = function(config, value) {
        var length = value ? value.length : 0,
            min    = config.min,
            max    = config.max;
            
        if ((min && length < min) || (max && length > max)) {
            return false;
        } else {
            return true;
        }
    }
  5. #5
    We committed the fix to SVN and reported to Sencha.
    http://www.sencha.com/forum/showthread.php?260257

    Thank you for the report!
  6. #6

    Resolved

    Thank you everyone, the issue is resolved for me after updating Ext.NET.
  7. #7
    Thank you for confirming.

    Sencha opened a ticket.

    So, we created an Issue to monitor. We will a Sencha fix when it appears.
    https://github.com/extnet/Ext.NET/issues/183

Similar Threads

  1. [CLOSED] GridPanel Batch Update does not send data
    By chrish in forum 2.x Legacy Premium Help
    Replies: 11
    Last Post: Feb 18, 2013, 3:38 AM
  2. Replies: 1
    Last Post: Feb 17, 2013, 3:49 PM
  3. Batch Update
    By shaileshsakaria in forum 2.x Help
    Replies: 1
    Last Post: Jan 18, 2013, 4:17 PM
  4. [CLOSED] MVC3 Data Annotations/Validation
    By adelaney in forum 2.x Legacy Premium Help
    Replies: 11
    Last Post: Aug 26, 2012, 8:06 AM
  5. Replies: 0
    Last Post: Apr 12, 2011, 3:32 PM

Tags for this Thread

Posting Permissions