- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2017 11:31 AM
Hello,
I have a Service Catalog Record Producer, with a list collector in the middle of the form. When the form loads, I want the focus to be at the top of the form, or at least set to the first editable field. In an onLoad Client Script I tried the following, individually, to no avail:
setTimeout ( "var refocus = g_form.getElement('table_name.field_name');refocus.focus();" , 0 ) ; }
------------------------------------------------------------------------------------------------------------------------------------
(function($) {
var fieldname = 'start_date';
$(g_form.getControl(fieldname)).focus();
})(jQuery.noConflict());
------------------------------------------------------------------------------------------------------------------------------------
And various other getElementById()
Here is how the form loads:
This is how I want it to load:
Thank you in advance,
Laurie
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2018 06:20 AM
Hi Anjaneyulu,
Actually, I discovered it was something else causing the focus not to be at the top of the page. We have a client script that displays a field message at the bottom of a field (which is in the middle of the form). I had to add the "false" parameter to the function. Without "false", the focus is set to that field with the message when the form loads.
function onLoad() {
g_form.showFieldMsg('u_ncpi_information','Sensitive NCPI Information should only be entered in the above box.','error',false);
}
Thanks,
Laurie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2017 02:22 PM
It's FIXED!!!! Works in Jakarta UI16!
Use the Chrome INSPECT tool, and click on where you want the focus. For my form, I clicked on the first editable field and got the below via Chrome Inspect:
<input id="sys_display.IO:ba96d7d26fed62004c3e841dba3ee4ed" name="sys_display.IO:ba96d7d26fed62004c3e841dba3ee4ed" class="questionsetreference form-control element_reference_input" onfocus="if (!this.ac) new AJAXTableCompleter(this, 'IO:ba96d7d26fed62004c3e841dba3ee4ed', '', '', 'sys_user');" onkeydown="return acReferenceKeyDown(this, event);" onkeyup="return acReferenceKeyUp(this, event)" onkeypress="return acReferenceKeyPress(this, event)" onpaste="return acReferenceKeyPress(this, event)" autocomplete="off" ac_columns="name;email" ac_order_by="name" value="Laurie Marlowe" role="combobox" aria-autocomplete="list" aria-owns="AC.IO:ba96d7d26fed62004c3e841dba3ee4ed" aria-activedescendant="">
Then I added the following code to my onLoad client script.
document.getElementById('sys_display.IO:ba96d7d26fed62004c3e841dba3ee4ed').focus();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2018 06:13 PM
Hi Laurie,
i tried this
document.getElementById('sys_display.IO:ba96d7d26fed62004c3e841dba3ee4ed').focus(); in onchange method.
my code is given below..
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
document.getElementById('sp_formfield_IO:0abf812e4fe70f00b4787bb28110c7f5').focus();
//Type appropriate comment here, and begin script below
}
but it is giving error like this..and i tried in jakarta u16.
How to solve this onfocus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2018 06:20 AM
Hi Anjaneyulu,
Actually, I discovered it was something else causing the focus not to be at the top of the page. We have a client script that displays a field message at the bottom of a field (which is in the middle of the form). I had to add the "false" parameter to the function. Without "false", the focus is set to that field with the message when the form loads.
function onLoad() {
g_form.showFieldMsg('u_ncpi_information','Sensitive NCPI Information should only be entered in the above box.','error',false);
}
Thanks,
Laurie