PDA

View Full Version : [CLOSED] Validation cell GridPanel



ermanni.info
Mar 05, 2013, 1:17 AM
Hello!

In an editable GridPanel have a column that represents the name of the city. For this column I added a validation through "Validator.Fn." In Validator I tell a function server side through DirectMethods.



textField.Validator.Fn = column.ChangeEvent;


Some strange things are happening:
- The value entered by the user is not recorded in the cell;
- The simple fact double click in the cell already does "Loading" appears;
- Every keystroke typed the same "Loading" occurs;

This is the default behavior of GridPanel? Is there an event that runs only when editing the cell is being completed?

Another need is to feed another GridPanel column when the cell is informed. In the example I cited the city name. If the user enters the name of the city correctly then return another column to record the ID found in the city. How do?

Thanks!

Ermanni

Baidaly
Mar 05, 2013, 5:01 AM
Hello!


Some strange things are happening:
- The value entered by the user is not recorded in the cell;
- The simple fact double click in the cell already does "Loading" appears;
- Every keystroke typed the same "Loading" occurs;
This happens due to call of direct method is asynchronous and browser doesn't wait the response from the server side. All other problems caused by using Validation you should use remote validation: http://examples2.ext.net/#/Form/Validation/Remote_Validation/


Another need is to feed another GridPanel column when the cell is informed. In the example I cited the city name. If the user enters the name of the city correctly then return another column to record the ID found in the city. How do?

I don't quite understand what you need can you provide example? As I understood you you should listen Success of remote validation.

ermanni.info
Mar 07, 2013, 1:44 AM

Baidaly
Mar 07, 2013, 4:15 AM
It's not possible to use remote validation with CellEditor plugin. http://forums.ext.net/showthread.php?15322-CLOSED-Need-help-in-GridPanel-Cell-Validation-%28Server-Side%29

However, you can use RowEditorPlugin http://examples2.ext.net/#/GridPanel/Plugins/RowEditor_Remote/ . Using RowEditor you can make remote validation.

ermanni.info
Mar 07, 2013, 10:48 AM
Baidaly,

Is there another way to validate using CellEditor in GridPanel?

Say I go RowEditor use. Solving the second question? How do I update a column in the grid based on this validation? (the way I explained in the previous post).

Thanks!

Ermanni.

Daniil
Mar 07, 2013, 11:22 AM
Hello,


Is there another way to validate using CellEditor in GridPanel?


Well, Vladimir suggests a possible solution in the post that @Baidaly referred.



Say I go RowEditor use. Solving the second question? How do I update a column in the grid based on this validation? (the way I explained in the previous post).

I think it is possible to do inside a success handler on a validation request.

ermanni.info
Mar 08, 2013, 12:30 AM

Baidaly
Mar 08, 2013, 3:07 AM
You should use the same approach as in example with DirectMethod due to DirectEvent called after JS handler of the Update button click.

ermanni.info
Mar 14, 2013, 4:05 AM
This approach to validation is not complete! Using the example (http://examples2.ext.net/#/GridPanel/Plugins/RowEditor_Remote/) provided (and this also happens with my application), press ENTER on the Salary field and change the value 47,000 to 47. Press ENTER again and the line is not validated. The grid supports a value less than 1.000. How to force validation to happen ever?

Thanks!

Ermanni

Baidaly
Mar 14, 2013, 5:01 AM
You should add validation for not phantom records:


[DirectMethod]
public object ValidateSave(bool isPhantom, JsonObject values)
{
if (!isPhantom)
{
if (!values.ContainsKey("salary") || Convert.ToInt32(values["salary"]) < 1000)
{
return new { valid = false, msg = "Salary must be >=1000 for old employee too" };
}
}

if (!values.ContainsKey("salary") || Convert.ToInt32(values["salary"]) < 1000)
{
return new { valid = false, msg = "Salary must be >=1000 for new employee" };
}

return new { valid = true };
}

ermanni.info
Mar 14, 2013, 10:28 AM
What is the concept of phantom records? Is there any difference when a record is phantom or not?

Thanks!

Ermanni.

Daniil
Mar 14, 2013, 10:59 AM
Please read:
http://docs.sencha.com/ext-js/4-2/#!/api/Ext.data.Model-property-phantom

Briefly, a record is added client side, but not saved to a persistent store yet.

ermanni.info
Mar 16, 2013, 1:00 AM
Understand the functioning of phantom, but I still have problems with the validation of grid. In the event I removed the validation test that identifies whether the line is phantom. Thus the validation always occur. Except that when I change an item and then immediately press ENTER without using the "Update" button no validation is performed.

Another problem that happens in the actual application that is editing the line is canceled when an incorrect value is reported. The alert is generated with the error message in the validation set. When I click OK in the alert editing the registry is canceled. At the time of creating the plugin RowEditing'm in AutoCancel by setting the value "false". What can cause this automatic termination when the data is invalid?

Thanks!

Ermanni

Daniil
Mar 18, 2013, 7:23 AM
Understand the functioning of phantom, but I still have problems with the validation of grid. In the event I removed the validation test that identifies whether the line is phantom. Thus the validation always occur. Except that when I change an item and then immediately press ENTER without using the "Update" button no validation is performed.


Please try this override. We will consider to add it into SVN.

Fix

Ext.grid.plugin.RowEditing.override({
getEditor: function () {
var me = this;

if (!me.editor) {
me.editor = me.initEditor();
if (me.editor.rendered) {
me.setHandlers();
}
else {
me.editor.on("afterrender", me.setHandlers, me); // single?
}
}
return me.editor;
},

setHandlers : function () {
if (this.saveHandler) {
var btn = this.editor.getFloatingButtons().down("#update"),
enterBinding = Ext.Array.findBy(this.editor.keyNav.map.bindings, function (b) {
return b.key === Ext.EventObject.ENTER;
});

btn.handler = this.saveHandler;
btn.scope = this.editor;

enterBinding.handler = this.saveHandler;
enterBinding.scope = this.editor;
}
}
});



Another problem that happens in the actual application that is editing the line is canceled when an incorrect value is reported. The alert is generated with the error message in the validation set. When I click OK in the alert editing the registry is canceled. At the time of creating the plugin RowEditing'm in AutoCancel by setting the value "false". What can cause this automatic termination when the data is invalid?


It seems to be not reproducible with the online example, is it? If yes, please provide your sample. If no, please provide exact steps to reproduce.

Daniil
Mar 18, 2013, 11:43 AM
It has been fixed in SVN and will be included into the next release.

Thank you for the report!