Autofocus cursor on form field when opening?
Autofocus cursor on form field when opening?
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?
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 V9 (latest build), Developer Edition, on OS Linux (Ubuntu) using GUI hosted on AWS EC2, MYSQL on AWS RDS
Re: Autofocus cursor on form field when opening?
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);
setTimeout (function () {
widget.element.find(".k-input").first().focus();
}, 400);
-
- Posts: 370
- Joined: Sat Apr 28, 2018 3:33 am
- Location: India
- Contact:
Re: Autofocus cursor on form field when opening?
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);
setTimeout (function () {
widget.element.find("#yourid").focus();
}, 400);
Re: Autofocus cursor on form field when opening?
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 V9 (latest build), Developer Edition, on OS Linux (Ubuntu) using GUI hosted on AWS EC2, MYSQL on AWS RDS
Re: Autofocus cursor on form field when opening?
did you click on SCRIPTS in the properties window and then select render script and enter it there?
Bruce
Bruce
Re: Autofocus cursor on form field when opening?
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:
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
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 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
Jaymer
Aware Programming & Consulting - Tampa FL
Re: Autofocus cursor on form field when opening?
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;
}
}
}
}
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;
}
}
}
}
Re: Autofocus cursor on form field when opening?
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
Jaymer
Aware Programming & Consulting - Tampa FL
-
- Posts: 620
- Joined: Wed Jun 17, 2015 11:16 pm
- Location: Omaha, Nebraska
- Contact:
Re: Autofocus cursor on form field when opening?
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
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
We specialize in enabling business through the innovative use of technology.
AwareIM app with beautiful UI/UX - https://screencast-o-matic.com/watch/crfUrrVeB3t
Re: Autofocus cursor on form field when opening?
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?Jaymer wrote:yuck !!!
Did I mention that?
Does it still have the "yucky" feel Jaymer?
Bruce