Validation message grid shows direct in IE, not in chrome/Opera

Sep 16, 2011 at 9:30 AM

Hi,

I made a grid with in that grid validationmessages. In Opera and Chrome they only show after I press the save button, but in IE they show up after I press the add new row button. Do you have any idea what could cause this?

Patrick

Coordinator
Sep 16, 2011 at 9:46 AM

What Kind of grid?

DatagridFor or grid with client side templates?

Sep 16, 2011 at 9:48 AM

datagridfor

Coordinator
Sep 16, 2011 at 10:26 AM

Ok I have seen it. 

New versions of browsers made a bug appears in the "changes tracking" module. Specifically, in the function that "clean" a row an put it in its initial state. I am working on it.

Quite strange, since i use jQuery. Maybe the problem is with the whole version of jQuery. I let you know.

Sep 16, 2011 at 10:28 AM

Thanks!

Coordinator
Sep 16, 2011 at 3:20 PM

I fixed the bug. The fix will be available in the next version of the toolkit, that I hope to put on lline the next week.

However, pls note that the normal behaviour is that the row is validated immediately when it is put in edit mode. The bug prevented this behaviour simply because it prevented also row cleaning. That is once you put a row in edit mode you continue to see your pevious edit, instead to having all field reset to their initial value.

Unlikely the only way to reset the validation state of a row is just to validate it again. All validation api...don't allow an input element be simply reset to its initial validation state. Thus the only way to cancel possible validation errors due to previous edit of a row is just validating the row again. That is why rows are validated as soon as they are put in edit mode.

Sep 16, 2011 at 4:32 PM

So this means whenever I add a new row the validation message will appear directly? Would it be possible to "extend" the bug and show after the add without the validation message and whenever you leave a field show an error for that field if one is there. (as now happens in Chrome)

Coordinator
Sep 16, 2011 at 7:22 PM

:) The problem is that the bug has also other side effects because the row is not cleaned at all. Suppose you insert a new row and then delete it. Then you create a new row again...then you will see the old values of the previous created row. 

Instead of validating the row I will try to cancel the visual effects of validation by removing the validation classes added to the errors and input filed to show the visual effect of validation...I can try this...not sure it will work without side effects. I will let you know.

Coordinator
Sep 16, 2011 at 8:14 PM

Ok I solved the problem, by simply working with the validation classes that are removed and added in case of errors. Now, validation is performed when appropriate.

Next Week I will post the new version of the toolkit so you can try it before I release the new version officially.

Sep 17, 2011 at 4:01 PM

Sounds great. Let me know when you post it and Ill test it!

Patrick

Sep 19, 2011 at 1:38 PM
Edited Sep 19, 2011 at 1:40 PM

Hey,

I probably found a related problem, maybe you can check that one out also. I have a record with a list in it. The list is managed by the mvc toolkit by the grid. When there is a serverside validation error, for example an id that exists I add that with the 

 ModelState.AddModelError(errorMessage.Key, errorMessage.Value);

after that I return the record to the form to correct the error. When the form tries to bind the list again to the grid there are null values in the record instead of the previously filled values and therefor it crashes. 

Is this related with bug you found?

Patrick

(I think it is something like the component uses the old values (whitch are null) to bind it instead of the new values?)

Coordinator
Sep 19, 2011 at 2:42 PM

MMM I don't think, but maybe, more likely you made some mistake. 

You mean a grid nested in a grid?

if yes, nested grid should work, but are not adviced for performance issues, because you nest two devices that do changes tracking, so there is a kind of explosion of "stored old values". I advice to use a SortableListfor if you need to insert it into each row of another grid. The SortableListFor can be used as a grid, it has sorting, paging, etc, but has no Changes tracking.

Anyway maybe the list is not bound because you have not included the name of the field containing the list among the fields whose old values need to be mantained by the grid, or simply you have done some name prefix error. Please show me your code.

Fields to be mantained can be specified with the toTrack parameter of the DataGridFor instruction. Below an example of use:

 .../*previous parameters*/, toTrack: new FieldsToTrack<ToDoItem>().
                                   Add(f => f.Code).Add(f => f.Name).Add(f => f.Description).Add(m => m.Important)
                                   .Add(f => f.ToDoRoles).Add(f => f.ToDoRole))

 

I prepared the 1.4.0 version of the toolkit. Please send me your EMail adress, so I send you the bits. NOT HERE, use the contact form of my blog: http://www.dotnet-programming.com/contact.aspx

Sep 19, 2011 at 2:54 PM

It is not a nested grid, but a grid in a normal record. I didnt had the toTrack item on, ill check it out now.

Patrick

Sep 19, 2011 at 3:18 PM

That did not do the trick.

When I look at the Model in the view after the validation error occured server side I see that the old value is null, the new value is filled and the changed state is true. 

The error I get is: The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.Int32'. This happens because of a custom control that does not allow null values, but also a similar error when using a dropdownlistfor: Object reference not set to an instance of an object. 

It has something to do with adding an existing record to the page and using I think first the oldvalue (which is null) and then fill it with the new value.

Patrick

Coordinator
Sep 19, 2011 at 3:42 PM

Now I understand what happens.

The grid has changes tracking, so it renders also the old version of the whole row (the one with the null values) and at this stage it get the error. After it shows the right row but it also render a row with the old values, to use it in case you press the undo row button, or the resetrow button.

In mvc you should always consider the possibility of a model to be null. Thus, it is good practice to always use ...for helpers that works fine also with null values. The extended dropdownlistfor included in the mvc controls toolkit should be able to work also with null lists.

What is the custom component that is not able to work with null values?

Sep 19, 2011 at 4:03 PM

I changed the dropbox to

    @Html.DropDownListFor(model => model.HasNss,
                ChoiceListHelper.Create( 
                    new List<KeyValuePair<bool,string>>(){
                        new KeyValuePair<bool,string>(false, @Global.No),
                         new KeyValuePair<bool,string>(true, @Global.Yes),
                    }, x=>x.Key, x=>x.Value
                    ))

And that worked.
For the other object I use the telerik integertextbox. http://demos.telerik.com/aspnet-mvc/numerictextbox 
Patrick

 

Sep 19, 2011 at 4:14 PM

fixt it also for the integer textbox. instead of using the editorfor and let it figure out what control to use with a template I now use directly the integertextboxfor component.

Ill now go test the new release!

Patrick