The CreatorCon Call for Content is officially open! Get started here.

How do I change the form or tab focus after a field changes?

russellj03
Giga Contributor

The system I work on displays a closure section when incidents are marked as closed, which is done with a drop-down menu vs. a UI action.   The section is off the screen, however, and it is confusing because users don't know it is there until they hit update and get an error popup.   I am trying to change the focus with a UI Policy or onChange Client Script, but nothing has worked so far.

In my Client Script, I know I have the field change detecting correctly because I have an alert popping up.   I have tried using the g_tabs2Sections API:

1) by putting in the section numbers directly (.setActive(2))

2) by looking up the section ID in the source and finding the index of that sysID (.findTabIndexByID(sysID)), which was returning 1.

Neither section number is setting the focus.   What am I doing wrong?

Here is the main part of the script:

var id = g_tabs2Sections.findTabIndexByID('section_tab.12345678...');

alert('id = ' + id);

g_tabs2Sections.setActive(id);

1 ACCEPTED SOLUTION

Hi Justin,



I don't know what's causing the issue, but you could try wrapping that part in a timeout:


setTimeout(function() {g_form.getElement('incident.close_notes').focus();},0);



That way it executes after the client script finishes- perhaps the element has to hold focus for the duration of the script execution. That sounds plausible.


View solution in original post

17 REPLIES 17

Thanks for the input Justin,



Just to clarify - what do your values 7,8 and 12 refer to here         if (newValue == 7 || newValue == 8 || newValue == 12) {



I assume this line can be dropped?


document.getElementId("label.incident.close_notes").hint = "Description of the actions taken to investigate and resolve this incident.";


Yes, you can drop the hint line.



In my case, the client script runs on change to the State field on the Incident table.   So oldValue and NewValue are the values of that field before and after the change the user made to that field.   In the case of incident.state, the field has integer values (even though the labels are text), so oldValue and newValue contain the integer values that represent those states.



You can get a look at the values by going to System Definition -> Choice Lists, and filtering on the table and field you care about.   In this case table=incident, element=state.   On my system the other values represent other closed states, so you might be able to leave out the 8 and 12.



Thanks,


Justin


That's what I thought Justin.



Many thanks, exactly what I was looking for.