Hide & Display Info Message From True/False Field

PB20201617
Kilo Contributor

There are workarounds to this, but none of them are exactly what I am looking to accomplish & I more or less want to know if this can be done at this point because I can't seem to figure it out.

  • I want a True/False field to control an info message being displayed on the form.
  • If the field is set to true, the message should show & if the field is set to false, the message should be removed.
  • There should not be a limit to the number of times the message can be shown / removed without reloading the form.
  • I want the message to be displayed at the top of the form opposed to below the field.
  • The message should be able to have HTML, which shouldn't be an issue for info message but becomes an issue if I go the field message route.
  • I do not want to clear all messages being displayed on the form when the value is set to false, rather only remove the message that is being controlled by the true/false field.

I've tried using both an onChange Client Script & a UI policy, but both seem to give me the same result. In the script below, I have a condition on the UI policy I am using set to run when my field is set to true. Additionally Isolate script is set to false.

Execute if true:

function onCondition() {
    g_form.addInfoMessage('Please note this info', 'myInfoMessage');
}

Execute if false:

function onCondition() {
	$j('#myInfoMessage').remove();
}

This almost works & gets very close to what I am looking for, however it acts very odd & will initially display the message when set to true, will remove the message when set to false, and finally will do nothing when set to true again.


I tried to get creative & thought maybe if I utilize the scratchpad to hold a count, then change the name of the message each time that I may be able to get different results. Sadly this was not the case & the code below does the same thing as the code above, however the alert does count up indicating to me that my script logic at the least appears to be working

Execute if true:

function onCondition() {
	if (g_scratchpad.message == null || g_scratchpad.message == ''){
		g_scratchpad.message = 1;
	} else {
		var num = g_scratchpad.message;		
		g_scratchpad.message = num + 1;
		alert(num);
	}
	var messageName = 'myInfoMessage' + g_scratchpad.message;
    g_form.addInfoMessage('Please note this info', messageName);
}

Execute if false:

function onCondition() {
	var messageName = '#myInfoMessage' + g_scratchpad.message;
    $j(messageName).remove();
}

 

Additionally with the code described above, I found that the message can be shown -> removed -> re-shown if I set the field to true, then click the X on the info message to remove it, then set the field to false (nothing happens as the info message was already removed with the X), and finally set the field to true again. I suspect this is similar logic to g_form.clearMessages() which I'm trying to avoid using, but none the less I found it interesting.

1 ACCEPTED SOLUTION

Hello,

Here is the code. Works for me should work for you:-

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var know=g_form.getValue('knowledge');
g_form.addInfoMessage('Please note this info', 'myInfoMessage');

if(know=='true')
{

$j('#myInfoMessage').show('');

}
else
{
$j('#myInfoMessage').hide('');


}

}

 

Please mark the answer as correct.

Thanks.

 

View solution in original post

11 REPLIES 11

Hitoshi Ozawa
Giga Sage
Giga Sage

The easiest way to accomplish the requirement seems to be to just add a read-only field at the top of the form to show the message.

Thank you, but I am not looking for the easy route. 


"There are workarounds to this, but none of them are exactly what I am looking to accomplish & I more or less want to know if this can be done at this point because I can't seem to figure it out."

Saurav11
Kilo Patron
Kilo Patron

Hello,

Write a Onchnage clientscript on the checkbox. Use the below box:-

Replace knowledge with your checkbox field name:-

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var know=g_form.getValue('knowledge');

if(know=='true')
{
g_form.addInfoMessage('test');
}
else
{
g_form.clearMessages();
}

}

 

Please mark correct/helpful based on impact

Thank you for this, however this script includes the line that prompted this question. 

g_form.clearMessages();

This will clear every message that is being displayed on the form, while I am trying to specifically remove the individual message handled by the field yet leave any other messages being displayed on the form.

I suspect I need to modify the line of my script to somehow hide the message opposed to removing it. Then if the field is set true, show the message again. It doesn't necessarily need to be removed, but rather just act similar to how Visible = true/false would on a field.

$j('#myInfoMessage').remove();