leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Focus an input or textarea

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?

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Focus an input or textarea

I've figured it out whilst trying to make the file upload work.
There is a Name property that can be set

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Focus an input or textarea

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:

Image

Set your id on the input field like this (make sure the id is unique!)
Image

then use it like this:
code$scope.setFocusTo("username-input");/code

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Focus an input or textarea

Hello Steve,

Please use method focus() for that: https://api.jquery.com/focus/

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Focus an input or textarea

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...

Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Focus an input or textarea

As is provided in the link by Sergiy $("target").focus where target is your control name. You could also use Appery ("target").focus

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Focus an input or textarea

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

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Focus an input or textarea

Hi Steve -- Could you please provide an app public link to test this?

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Focus an input or textarea

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

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Focus an input or textarea

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?

Return to “Issues”