Autofocus cursor on form field when opening?

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
RLJB
Posts: 914
Joined: Tue Jan 05, 2010 10:16 am
Location: Sydney, Australia

Autofocus cursor on form field when opening?

Post by RLJB »

Anyone have a script to do this? Please share?

There is this:
https://awareimdevelopers.com/tipsntric ... k-version/

But it looks a bit old, pre Aware Scripts feature and ID, maybe a better way now?
Rod. Aware 8.6 (latest build), Developer Edition, on OS Linux (Ubuntu) using GUI hosted on AWS EC2, MYSQL on AWS RDS
BLOMASKY
Posts: 1470
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Re: Autofocus cursor on form field when opening?

Post by BLOMASKY »

I know you said form field, but to share, I use this in my render scripts for queries, to set the cursor to the 1st field (which, in many cases, is a filter).

setTimeout (function () {
widget.element.find(".k-input").first().focus();
}, 400);
swiftinitpvtltd
Posts: 370
Joined: Sat Apr 28, 2018 3:33 am
Location: India
Contact:

Re: Autofocus cursor on form field when opening?

Post by swiftinitpvtltd »

In addition to what suggested above you can also give specific ID in aware properties of the first control of form and then use
setTimeout (function () {
widget.element.find("#yourid").focus();
}, 400);
RLJB
Posts: 914
Joined: Tue Jan 05, 2010 10:16 am
Location: Sydney, Australia

Re: Autofocus cursor on form field when opening?

Post by RLJB »

Sorry guys doesn't work for me.. I tried the script on the FORM and the FORM section... no love. Any further tips?
Rod. Aware 8.6 (latest build), Developer Edition, on OS Linux (Ubuntu) using GUI hosted on AWS EC2, MYSQL on AWS RDS
BLOMASKY
Posts: 1470
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Re: Autofocus cursor on form field when opening?

Post by BLOMASKY »

did you click on SCRIPTS in the properties window and then select render script and enter it there?

Bruce
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Autofocus cursor on form field when opening?

Post by Jaymer »

doesnt work for me

console error: VM32871:2 Uncaught ReferenceError: widget is not defined
at eval (eval at runScript (aware.js?V2709:1), <anonymous>:2:1)

I put this code in the Section Render Script - I have 3 Sections and need to set focus on a field when I click on the 2nd Section:

Code: Select all

setTimeout (function () {
widget.element.find(".k-input").first().focus();
}, 400);
For reference, we need to realize there are Init & Render scripts available for BOTH the Form and each Section (tab).
For testing, I actually put this in Form Render, and both Section Renders.
I get the same error. "widget" is not correct here
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
BLOMASKY
Posts: 1470
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Re: Autofocus cursor on form field when opening?

Post by BLOMASKY »

AwareApp_FormParser.prototype.setFocus=function(sectionName) {
if (this.m_fields ) {
var firstTabIdx = null, focusSet = false;
for (var i = 0, len = this.m_fields.length; i < len; ++ i) {
var f = this.m_fields ;
var tabIndex = f.getTabIndex ();
if (tabIndex && tabIndex == "1") {
firstTabIdx = f;
if ((! sectionName || sectionName == f.getSectionName ()) && f.setFocus ())
focusSet = true;
break;
}
}
if (! focusSet) {
for (var i = 0, len = this.m_fields.length; i < len; ++ i) {
var f = this.m_fields ;
if (f != firstTabIdx && (! sectionName || sectionName == f.getSectionName ()) && f.setFocus ())
break;
}
}
}
}
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Autofocus cursor on form field when opening?

Post by Jaymer »

yuck !!!
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
johntalbott
Posts: 619
Joined: Wed Jun 17, 2015 11:16 pm
Location: Omaha, Nebraska
Contact:

Re: Autofocus cursor on form field when opening?

Post by johntalbott »

If this just needs to work for the first tab of the form when it first opens, here is a simple approach.

Form Render Script

Code: Select all

setTimeout(function(){
     $("input[name=FirstName]").focus()
}, 500)
VocalDay Solutions - Agility - Predictability - Quality

We specialize in enabling business through the innovative use of technology.

AwareIM app with beautiful UI/UX - https://screencast-o-matic.com/watch/crfUrrVeB3t
BLOMASKY
Posts: 1470
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Re: Autofocus cursor on form field when opening?

Post by BLOMASKY »

Jaymer wrote:yuck !!!
You say "YUCK" but did I mention, that I have that in a "custom.js" file in my custom folder and I don't have to do anything to each form? This is a global function that will always set the cursor into the 1st field of each and every form with out any scripts in each one?

Did I mention that?
Does it still have the "yucky" feel Jaymer?

Bruce
Post Reply