Validation between that depends on two fields in a ListGrid

Hi,

I have a list grid which has two columns. Column A = min and column B = max. For each row, min must be greater than 0 but smaller than the “max” of the same column. Obviously, the “max” can be different in each column.

Is there a way to do a validator that uses the value of another cell in it’s rule?

Regards,
Maxime

The simplest thing here is probably to use the Changed event and call setFieldErrors().

That’s an excellent suggestion but according to http://code.google.com/p/smartgwt/source/detail?r=404, setFieldErrors is not available in SmartGWT-1.0b2 :frowning:

Maybe I could do a JSNI call to call setFieldErros. Does anyboy know how to do it?

setFieldErrors() is there if you build from SVN.

I can’t build from SVN. My company requires that we only use official releases of third party software.

I looked at the source code in SVN and here is the required JSNI code required:

protected native void setFieldError(ListGrid grid, int rowNum, String fieldName, String errorMessage) /-{
var jsGrid = grid.@com.smartgwt.client.widgets.BaseWidget::getOrCreateJsObj()();
jsGrid.setFieldError(rowNum, fieldName, errorMessage);
}-
/;

Thanks a lot for your help!

There is a problem with the solution above. When calling setFieldError from within OnCellSaved (CellSavedHandler callback), the error is not shown to the user correctly. Here are my repro steps:

  • click in a cell
  • edit value to enter something invalid
  • press tab so that the CellSavedHandler is called

At that point, the cell displays the error message properly but as soon as I click on another error, the error message disapears.

Also note that calling any method on the CellSavedEvent object passed to onCellSaved throws an exception.

So, this overall strategy does not work properly. I tried to fix the problem for a few hours but I fell back on doing the validation when the user tries to apply the current form.

We hereby bless last night’s nightly as “beta 2.5”. You can now use it :wink: Kidding only serious, as we can’t really take the time to look into bug reports from older builds while all builds are still betas.

A manually set validation error is going to get cleared any time validation is rerun for that cell, and any time the record is successfully saved (since it must be valid to be saved). See setValidateByCell(), setSaveByCell() and related APIs, and think about the lifetime you want for your custom error. The simplest thing might be to re-run your validation over the whole grid (this one is presumably small) every time there’s a save, even if that’s on every cell transition.