Default Focus Field on Incident Form Load

rosa8
Mega Contributor

I have a request to set the default focus field on the Incident form to Additional Comments after the initial save. I'm thinking this should be an easy task but I'm not having any luck.

I was able to get it to partially work on an onChange Client script on the Clock No. field but it has some issues when creating a new incident. The code is as follows.



function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading && newValue == '') {
return;
}

if (newValue != ''){
var field = g_form.getControl('comments');
field.focus();
}
}


When I try to use the onLoad Client Script I can't get it to work at all. I get the alerts to pop up but the focus is still at the caller_id field.



function onLoad() {
var clock = g_form.getValue('caller_id');
alert(clock);

if(clock != ''){
alert('Running if statement.');
var field = g_form.getControl('comments');
field.focus();
}
}

14 REPLIES 14

Thanks a lot Jim that worked perfectly however my requirement has changed slightly I have now been asked to make the focus on close notes if the incident state is 7 or 8 so I had a play and thought this code might work but it doesn't!



function onChange(control, oldValue, newValue, isLoading, isTemplate) {  


      if (isLoading || newValue == oldValue || newValue == 8 || newValue == 7) {  


              return;  


      }  


      window.setTimeout(u_highlightCloseNotes,0);  


}  


 


 


function u_highlightCloseNotes() {  


      try {  


                // g_tabs2Sections.setActive(4);  


              document.getElementById('incident.close_notes').focus();  


      } catch(err) {};  


}



My coding is rudimentary at best unfortunately.


Try this line instead:



if (isLoading || newValue == oldValue || (newValue != 7 && newValue != 8)) {


Perfect Jim, many thanks


You are welcome.


Jim - what would I need to do to make this work on a Record Producer?