How to stay focused on form field? - forms

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.

Related

How can I toggle a hidden element based on user input (text field)?

I'm looking for a good way to reveal a hidden element (a div) based on specific input into a form field. The application is an order form that isn't using any database. I want to have users input a coupon code and if it matches have the div appear (which contains what is needed to do the discount). And if it doesn't match it either does nothing, loads another hidden element or reveals a message like "invalid code".
PHP would be preferred but I'm open to anything. I don't see how the textbox where users enter the code has to be submitted with a submit button as it would submit the order form. It isn't critical that the discount is 100% secret. In other words, if they think to view the source code to see if they can figure out if there's a discount then they've earned it.
I've thought about using a inline frame for simplicity but I don't think that will work.
You could use the input's oninput function to watch the value entered. On each keypress you could make a call to see if it matches a coupon code. If the coupon codes are always "x" length, you could only do the call when the value reaches that length (if you don't want to call on every single keypress).
Alternatively, you could use a button and use it's onclick attribute. It would be the same idea as above, just instead of making the call on every keypress, you would only make the call on the button's click.
Once the value matches, just set the hidden div from "display: none" to "display: block" or something like that.
oninput reference
onclick reference

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("");

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.

GXT 3 spinnerField validation

I want to validate that user cannot change spinner value manually by typing in text box of spinner.
For example a field sales multiple = x which I fetched from server not fix.
and displays a spinner field with limitation of like bellow
spinner.setMinValue = x
spinner.setIncrement = x
spinner.setValue = x
so user forcefully select a value which is multiple with x. e.g. if x=3 the user have to enter 3,6,9... and so on.
So here my issue is if I type a 2 in spinner field text box. GXT widget accept that value.
Posible solutions:
Is there any predefined properties of spinnerfield that i forget to set it?
Is there any predefined validator for this?
Can I set text box of spinner field read only by css so user cannot focus on text box but still change a value.
If none of above how to achieve manually?
i've searched a bit in the different classes and I don't see either a precise method which would set what you want.
Don't know about one, and even with one, a validator doesn't change the value in the input field, but maybe it's enough for your needs.
You can disable the text input by calling setEditable(boolean) on the spinnerfield (testSpinner.setEditable(false);)
Maybe you could search around the IntegerPropertyEditor, I haven't tried but as long as a new Spinner is like this:
SpinnerField<Integer> testSpinner = new SpinnerField<Integer>(new NumberPropertyEditor.IntegerPropertyEditor());
you can seen that there is another Constructor for IntegerPropertyEditor, which takes a "NumberFormat" param, but there is no NumberFormart() constructor, so I'm not sure about how you create your own one, but that could be an idea (to format numbers in the input to be a multiple of the increment).
The last option would be that Sencha forgot this possibility and that you should report this as a "bug" on the forum ?
Hope to have helped a bit, good luck :).

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)