WicketTester: Determine which component has focus - wicket

I have a form that focuses a different component based on state when it loads. Is there a way with WicketTester, or some other Wicket test tool, to determine which component currently has focus?
For example, a form with username and password. When username is present then the password field gets focus and when it is not present username field gets focus.
Here is how I set focus in a temporary Behavior...
response.render(OnDomReadyHeaderItem.forScript("document.getElementById('" + component.getMarkupId() + "').focus();"));

since you use an headerItem to set the focus, you could test the html of the last rendered page. For example:
String responseTxt = tester.getLastResponse().getDocument();
assertTrue(responseTxt.contains("document.getElementB‌​yId('componentId').focus();"));

Related

How to flag an invalid entry with CellRendererText

I'm writing an application with tables full of user-editable data. Some of the table columns contain numbers. I want the user to be able to type a new number in to a field in the table, but if the user types "foo" or "1.2.3" I need to be able to signal to the user that this has not been accepted.
When using a normal Entry widget I can set the state to Invalid if the user enters something that is not a number. However for the tables I'm using TreeView with TreeViewColumns. The user is editing text displayed with CellRendererText. I know that I can get the actual text entry widget while the user is entering text, but as far as I can tell when the user presses "Enter" that widget goes away before the CellRendererText sends the TextEdited signal.
What is the right way to signal to the user that they have typed in the wrong thing in this circumstance? I'd like to do something like outlining the offending field in red.
You can connect to editing-started to get the TextEntry object, and then connect to the changed signal to watch what the user is typing. After that you can hint a problem with the text.

How to clear a SAPUI5 input field with only value help input allowed?

my SAPUI5 app has an input field where the valid values must be obtained through a value help:
<Input showValueHelp="true" valueHelpOnly="true"
valueHelpRequest="onValueHelpRequest"
value="{myModel>/myField}"
The value help is realized with a SelectDialog, where the only options are
choose one or
cancel
The problem is now the following flow:
User opens value help dialog to choose one item and presses Confirm
Input field now displays chosen value
User wants to clear the input, because it's optional
Unfortunately,
sap.m.Input doesn't provide a clear button
sap.m.SelectDialog doesn't provide the possibility to add a custom button like Clear
The input is layed out in a SimpleForm with 2 columns, labels and input fields, so it would be hard to add a clear button
The Gateway entity set which feeds the value help dialog list doesn't have a totally empty line
I don't like the workaround to switch the SelectDialog to multiSelect just for the purpose that the user can choose "one or none". I also think it would be hard to explain to the user "if you want to remove the value, hold the control key and click on the previously selected item again".
Any ideas out there how to easily implement a clear button or something similar?
valueHelpOnly="false"
// with this user can either fill by F4 (assisted input) or by typing input..
and if you want to clear you can add a button and set the value to null
oInput.setValue("");

How to stay focused on form field?

I have a form with multiple inputs and buttons for the user. At the start, only the first input is enabled and a few of the buttons.
When the first input is entered, (when the user presses enter), if there is no input or if the input is invalid, then I want the focus to stay on the input field. But when i try using MyControl.setFocus(), the focus is not staying on the field.
How is it possible to keep focus on the same field in this situation?
Using setFocus in the modified method of a form control is a no-go, as it confuses AX tab order.
You could make the conditional setFocus call from the enter method of the next field control.
It is not bullet proof, back tab is not handled, but is might do it for you.
The invalid case should be handled by the validate (or better validateField if a bound field), method of the first field.
Also consider setting the Skip property on display only fields.
You can return false from the modified() method (AX 2012 R3) and this too seems to prevent the focus from leaving.

Wicket's input looses behavior after the form it's in is submitted

I have a form and a series of panels containing inputs inside it, as a list. When I click the add button, the form is submitted and a new item is added into this form. Input inside a newly created panel gets date-picking behavior. The problem is that it cancels behavior applied to inputs which already were on that form (added previously). Inputs in other forms are not affected.
Each field behavior is applied onto has unique name. Values inside inputs are processed correctly.
How to preserve behavior applied on old inputs?
How to preserve behavior applied on old inputs?
You probably put your input fields into a ListView, right? If so, try calling ListView.setReuseItems(true). This setting makes sure that when you add something to the listview and it is rendered again that the old items (with the old input fields and their behaviors) will be kept instead of creating new ones.

Can I not remove the return key on the keyboard? Or at least change its text to "Set"?

I am creating a sign up page for my iphone app and am having some problems making the way the input views work for the different kinds of fields consistent. The fields are listed as cells in a table view and the editing is supposed to take place directly in the table by having appropriate input views sliding up from the bottom.
Let me focus on only two of the fields here, namely the username field and the birthday field: for the username field it makes sense to have an ASCII capable keyboard sliding up when the user presses the field whereas a date picker seems more useful in the birthday field case.
For both the keyboard and the date picker the cancel button could be located in a tool bar just above the input view. But what about the set button? If I put that in the toolbar as well I need the return key in the keyboard to go away! But that is not possible is it?
If the return key cannot be removed then I might have to live with the set button in the toolbar only in the birthday case and then use the return key as the set button in the username case - but can I then at least change the text on the return key to "Set"?
No it's not possible* to hide the "Return" key.
It is not possible to set the string to "Set" either, but could use the .returnKeyType property to change it to a limited set of strings.
theTextField.returnKeyType = UIReturnKeyDone;
(* Well you could put an opaque UIView directly above it but it's a very bad practice and generally breaks if the user chooses a different input method)