How to imitate mandatory like behavior on a field in UI Action

ican
Tera Contributor

Use Case:

I want to implement the mandatory behavior wherein after clicking the UI Action, after certain check if true it will highlight the field with red and sets the focus on that field.

 

I have tried:

 

if(condition == true) {
   var field = g_form.getControl('field');
   field.focus;
   field.style.border = '1px solid red';
   g_from.addErrorMessage('Error Message');
}

 

the field.focus will trigger the blue highlight on the field and it will be mixed with my field.style.border which is 1px solid red.

 

How to highlight it red and sets focus on that field.

 

Thanks.

4 REPLIES 4

Moin Kazi
Kilo Sage
Kilo Sage

Hi @ican 

 

There was a typo error in your script.

You can create onClick() UI action and put below code under this -

function onClick(){
   var field = g_form.getControl('short_description');
   field.focus;
   field.style.border = '1px solid red';
   g_form.addErrorMessage('Error Message'); // typo g_from corrected to g_form
}

Output:

MoinKazi_0-1729693628694.png

 

Hope this help you.

 

Regards

Moin

 

 

ican
Tera Contributor

yes, its just a typo while i formulate this question.

but it is not like that in the actual code.

thanks for the reply though.

 

anyways i got this already.

i just defined the box shadow of that field then its all good.

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

You can define field style for when the field values changes 

Define field styles (servicenow.com)

-Anurag

thanks for the reply.

i got the solution to this already.

thanks.