Page 1 of 2
Focus an input or textarea
Posted: Sun Feb 07, 2016 2:31 pm
by leven.steve
How do you set focus to an input or textarea component?
I have tried many things that I've seen in answers here but none appear to work (anymore?)
As the component "name" isn't carried through at runtime and it doesnt appear to have an "id" either how is it possible to address any item at runtime to focus it or add/change an attribute?
Focus an input or textarea
Posted: Sun Feb 07, 2016 2:39 pm
by leven.steve
I've figured it out whilst trying to make the file upload work.
There is a Name property that can be set
Focus an input or textarea
Posted: Sun Feb 07, 2016 2:46 pm
by leven.steve
Solved - there is a "Name" property that can be set manually for INPUT or add your own "id" attribute.
To make this easy to use create a scope function in the index page then you can use it anywhere in the app:
Set your id on the input field like this (make sure the id is unique!)
then use it like this:
code$scope.setFocusTo("username-input");/code
Focus an input or textarea
Posted: Mon Feb 08, 2016 6:54 pm
by Serhii Kulibaba
Hello Steve,
Please use method focus() for that: https://api.jquery.com/focus/
Focus an input or textarea
Posted: Tue Feb 09, 2016 8:05 am
by leven.steve
But how do I address the component? Could you provide an example of the component naming and the syntax for the focus() command please?
This would probably be of interest to others...
Focus an input or textarea
Posted: Tue Feb 09, 2016 8:20 am
by Joe Bohen
As is provided in the link by Sergiy $("target").focus where target is your control name. You could also use Appery ("target").focus
Focus an input or textarea
Posted: Tue Feb 09, 2016 9:19 am
by leven.steve
Thanks but both
$("nameInput").focus();
and
Appery("nameInput").focus();
produce these errors in the Chrome console:
ReferenceError: $ is not defined
ReferenceError: Appery is not defined
Just in case it was a typo, I tried Apperyio("nameInput").focus();
and got ReferenceError: Apperyio is not defined
Focus an input or textarea
Posted: Tue Feb 09, 2016 10:56 am
by Illya Stepanov
Hi Steve -- Could you please provide an app public link to test this?
Focus an input or textarea
Posted: Tue Feb 09, 2016 11:44 am
by leven.steve
RossTrustees, login lucia/lucia,
Menu option Configuration - Rates
Try editing the "Test" entry or click the Add button.
When the entry area appears I want it to focus to the Name input field
Focus an input or textarea
Posted: Tue Feb 09, 2016 3:24 pm
by leven.steve
Looking at this further and with reference to your post here https://devcenter.appery.io/documenta...
which shows using $ (jQuery?) to address an object/field I thought I would try this in my function code:
code $('[name="nameInput"]').focus();/code
But I get the same ReferenceError: $ is not defined
However if I breakpoint at that line and type it into the console it doesnt give an error.
Why?