- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 08:26 AM
Hey Everyone,
Below is my code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var citizen = g_form.getValue('variablename');
if (citizen === 'variablenameoption1') {
g_form.showFieldMsg('variablename, 'Please be aware ** minimum of 2 business days advance notice required **', 'info');
}
else if (citizen === 'variablenameoption2') {
g_form.showFieldMsg(''variablename', 'Please be aware ** minimum of 20 business days advance notice required **', 'info');
}
else {
g_form.hideAllFieldMsgs();
}
}
Basically, when I select the options 1 or 2 twice it doesn't clear the previous message. Do I need to add more to the if condition? Or is there a simpler way to do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2023 02:29 AM
I think whenever onchange gets executed, you can clear the message first and then execute your all the conditions.
Please refer the code below and in this case you don't need to write the else condition.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var citizen = g_form.getValue('variablename');
g_form.hideAllFieldMsgs();
if (citizen === 'variablenameoption1')
g_form.showFieldMsg('variablename, 'Please be aware ** minimum of 2 business days advance notice required **', 'info');
else if (citizen === 'variablenameoption2')
g_form.showFieldMsg(''variablename', 'Please be aware ** minimum of 20 business days advance notice required **', 'info');
}
Please try this code and let me know if you have any issues!
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2023 01:36 AM
Hi @Kenisha1 ,
Here is an non tested code you can give a try
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
g_form.hideAllFieldMsgs();
return;
}
var citizen = g_form.getValue('variablename');
if (citizen === 'variablenameoption1') {
g_form.showFieldMsg('variablename', 'Please be aware ** minimum of 2 business days advance notice required **', 'info');
}
else if (citizen === 'variablenameoption2') {
g_form.showFieldMsg('variablename', 'Please be aware ** minimum of 20 business days advance notice required **', 'info');
}
else {
g_form.hideAllFieldMsgs();
}
}
It will hide all field messages if the form is still loading or if the variablename field value is empty. It will show the appropriate message depending on the selected option and hide all messages if an invalid option is selected.
Regards,
Shravan
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2023 02:29 AM
I think whenever onchange gets executed, you can clear the message first and then execute your all the conditions.
Please refer the code below and in this case you don't need to write the else condition.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var citizen = g_form.getValue('variablename');
g_form.hideAllFieldMsgs();
if (citizen === 'variablenameoption1')
g_form.showFieldMsg('variablename, 'Please be aware ** minimum of 2 business days advance notice required **', 'info');
else if (citizen === 'variablenameoption2')
g_form.showFieldMsg(''variablename', 'Please be aware ** minimum of 20 business days advance notice required **', 'info');
}
Please try this code and let me know if you have any issues!
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2023 08:01 AM
Thank you so much!!! I knew it was just a little change to my logic. You were so helpful!!!!