0
votes

I have some dependencies hierarchy on my form, so I implemented hierarchy check on server side of the scout. If one field is changed, it triggered check if other need to be changed as well. This is done with export/import form data.

MyFormData input = new MyFormData();
FormDataUtility.exportFormData(this, input);
input = BEANS.get(IMYService.class).validate(input, field);
FormDataUtility.importFormFieldData(this, input, false, null, null);

validate function change all other fields that need to be changed.

My problem is with editing cells in editable tables.

If I change value in cell, and this chain validation is triggered, after importing form data I lose focus in cell. So instead, tab will move me to another cell, tab trigger import and focus in cells are lost. And this is a really bad user experience.

How to fix this? How to stay in focus (of next cell) after import has been called?

Marko

1

1 Answers

0
votes

I am not sure, if this applies for you, but you can try the following:
I assume, that you do your export/validate/import logic in the execCompleteEdit(ITableRow row, IFormField editingField) of your column class. I suggest, that you calculate your next focusable cell by yourself and request its focus after importing the form data.
As an example, you can do this like that:

    @Override
    protected void execCompleteEdit(ITableRow row, IFormField editingField) {
       super.execCompleteEdit(row, editingField);
       // create form data object
       // export form data
       // call service and validate
       // import form data
       // request focus for next cell
       focusNextAvailableCell(this, row);
    }


with focusNextAvailableCell(this, row) as following:

private void focusNextAvailableCell(IColumn<?> col, ITableRow row) {
    if (col == null || row == null) {
        return;
    }
    IColumn<?> nextColumn = getColumnSet().getColumn(col.getColumnIndex()+1);
    ITableRow nextRow = getTable().getRow(row.getRowIndex());
    if (nextColumn == null) {
        // no next column (last column lost focus)
        // check if next row is available
        nextRow = getTable().getRow(row.getRowIndex()+1);
        // maybe select first cell again?
        if (nextRow == null) {
            nextColumn = getColumnSet().getColumn(0);
            nextRow = getTable().getRow(0);
        }
    }

    if (nextColumn != null && nextRow != null) {
        getTable().requestFocusInCell(nextColumn, nextRow);
    }
}

You should be aware, that you have to call this after every form data import in your execCompleteEdit method of your column. Also this is triggered not only when switching cells through pressing the tab key, but also when clicking with the mouse button.

Best regards!