How to change a field value on UI page from the client script?

Kalyani
Tera Contributor

Hi All,

Please find the scenario below:

I have a UI page with 4 fields. When the field value for one field (field A) changes, I need to check if other three fields are empty or filled. If the three fields are empty, I need to display a message on the UI page to request the user to fill in other three fields. And also, wipe off the value of field A which the user first entered.

g_form.setValue("fieldA","") in the client script of UI page doesn't work

Please suggest a way to achieve it

Thank you

 

1 ACCEPTED SOLUTION

so you want to empty your html field. i thought you want to empty normal form field.

 

you should use below two line instead of g_form.

 

gel('sys_display.handover_by').value = "";

gel('handover_byLINKreplace').style = 'visibility: hidden; display: none;';

 

Note: I have tested it on my personal instance. 

 

If my answer helped you , kindly mark it as correct and helpful.

 

View solution in original post

6 REPLIES 6

MrMuhammad
Giga Sage

g_form.setValue() does work in UI Pages client script. May be the value you are trying to set is empty/undefined. Can you please put an alert and see if you are getting the value in the source variable?  

Regards,
Muhammad

ChrisBurks
Giga Sage

I believe g_form works on a UI Page when it's associated with a GlideDialogWindow and getting/setting values from a table form.

It doesn't work on elements that don't belong to a table in UI Pages.

To get/set values on elements on a UI page that aren't on a table you can use a couple of different options:

- vanilla javascript such as document.getElementById, getElementByClass, querySelector etc.

- system jQuery such as $j('selector')

- gel('selector')

- Prototype using double dollar sign: $$('selector')

Here are some screenshots showing this console logging out the usages:

find_real_file.png

 

UI page as a standalone page:

find_real_file.png

 

The same UI Page used through GlideModal:

find_real_file.png

 

Hopefully this helps

Harsh Vardhan
Giga Patron

just want to clear here, g_form works. either you use setValue() or getValue() it will work. 

 

as @chris already explained it 

 

Adding example here. 

 

find_real_file.png

 

Result:

 

find_real_file.png

 

 

Hope its clear and helped you. 

 

If my answer helped you , kindly mark it as correct and helpful.

 

 

 

 

Kalyani
Tera Contributor

Hi All,

Thank you for your response

Please find the attached code for reference. 

I am able to extract the values in the fields by using gel

However, the requirement is, that, if values in three fields are empty, I need to wipe the value in the fourth field (which is a reference field)

I have also tried g_form.setValue('handover_by',"");

But it is not taking off the value.

Please suggest in case if I'm doing anything wrong in the code, or in case if there is any other way of achieving this