I have a DynamicForm
with a TextField
placed in it. They are in a custom controller's view (like a form).
When user types some text in this field, the ListGrid
with available(suitable) textvalues is shown.
This ListGrid
retrieves data from server through DataSource fetching
. In dataArrived event
I have some logic, and make a decision to send another server request or not, and put focus into TextField
.
form.focusInItem(item);
Strange behaviour takes place in IE. After data arrives, cursor is put at the very beginning of the TextField.
In Mozilla, Chrome after data arrives, textfield can lost focus(even after being focused). And focus is placed somewhere else(somewhere between textField and advice grid). I can Tab to next control on my controller's view and then Shift+Tab back to the TextField
.
Have no idea why it happens. Can't see anything strange while debugging it. Maybe someone faced a problem like this with SmartGWT text controls?
Reasons for this strange behaviour were found.
//> @method formItem.getSelectionRange() // For text-based items, this method returns the indices of the start/end of the current // selection. Returns null if the item doesn't have focus. // <P> // Notes: // <UL> // <LI>In Internet Explorer, if the item has lost focus since the selection was made, // only the start (current caret position) is returned. This is a limitation of Internet // Explorer.</LI>
// If the item doesn't have focus always return null
// Natively the method we use in Moz would give us back the last selection, but the
// method we use in IE can't give us anything meaningful.
Taken from from FormItem.js
So, after server returns us a portion of data(dataArrived event), the data fetched into ListGrid
and TextField
lost focus. When we manually put focus back to text field(form.focusInItem(item);
), the selection is (0,0) - the beginning of the field. But only in IE. So we must save last selection before fetching data and then apply this selection after focus was manually put back to the text field.
And after all data operations and before putting focus and setting selection we must do form.redraw();