How to set focus on a Record Producer form?

Laurie Marlowe1
Kilo Sage

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:

Capture.PNG

This is how I want it to load:

capture2.png

Thank you in advance,

Laurie

1 ACCEPTED SOLUTION

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


View solution in original post

7 REPLIES 7

Laurie Marlowe1
Kilo Sage

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();


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.


find_real_file.png


How to solve this onfocus


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