Change lable on buttons in audit workspace g_modal.confirm popup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2024 09:47 AM
Hello All,
I'm trying to change the button labels on this popup from Cancel and OK to Yes and No. Tried switching to g_modal.showFrame and then the functionality was not working properly. Is there a way to change the label in g_modal.confirm? Both client scripts are currently working, just need to change the labels on the buttons for the workspace. Any help is appreciated. Thanks.
Note: UI page is being used for different client script with same functionality on desktop view. Desktop version works fine.
Client Script: Desktop
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if ((oldValue != '3' || oldValue != '4' || oldValue != '7') && (newValue == '3' || newValue == '4' || newValue == '7')) {
var myActionCallbackOK = function() {
submitRemediationNow();
};
var myActionCallbackCancel = function() {
cancelRemediationNow(oldValue);
};
var dlgBody = 'Are you sure you want to continue?';
var dlgClass = typeof GlideModal != 'undefined' ? GlideModal : GlideDialogWindow;
var dlg = new dlgClass('glide_confirm_remediation');
dlg.setTitle('Proceed?');
dlg.setPreference('warning', true);
dlg.setPreference('title', dlgBody);
dlg.setPreference('onPromptComplete', myActionCallbackOK.bind(this));
dlg.setPreference('onPromptCancel', myActionCallbackCancel.bind(this));
dlg.render();
}
}
function submitRemediationNow() {
//g_form.save();
}
function cancelRemediationNow(previewState) {
g_form.setValue('state', previewState);
}
Client Script: Audit Workspace (when either closed states is selected, the popup needs to appear with yes and no buttons, when no is clicked, state reverts back to previous value, when yes is clicked, need to save the record with newValue state)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if ((oldValue != '3' || oldValue != '4' || oldValue != '7') && (newValue == '3' || newValue == '4' || newValue == '7')) {
return confirm();
}
function confirm() {
g_modal.confirm("Have you received a notification from the tester?").then(function() {
g_form.save();
return;
}).catch(function() {
g_form.setValue("state", oldValue);
});
}
}
UI Page: glide_confirm_remediation (Desktop)
<style>
/* dialog styles */
.dialog_content {
width: 100%;
vertical-align: top;
min-width: 300px;
padding: 0 0 20px 20px;
}
.dialog_buttons {
display: inline;
text-align: right;
vertical-align:bottom;
white-space: nowrap;
}
.dialog_buttons_row {
text-align: right;
}
.dialog_left_icon {
font-size: 300%;
vertical-align: top;
}
.dialog_left_icon_warn {
color: #81878E;
}
.dialog_left_icon_confirm {
color: #6CE474;
}
</style>
<g:ui_form onsubmit="return invokePromptCallBack('ok');">
<g2:evaluate>
var title = "${RP.getWindowProperties().get('title')}";
title = new GlideStringUtil().unEscapeHTML(title);
var warning = "${RP.getWindowProperties().get('warning')}";
warning = new GlideStringUtil().unEscapeHTML(warning);
</g2:evaluate>
<table border="0" width="100%">
<tr>
<td nowrap="true" style="vertical-align:top;">
<j2:switch on="$[warning]">
<j2:case value="true">
<i id="image_dialog" class="dialog_left_icon dialog_left_icon_warn icon-alert-triangle"/>
</j2:case>
<j2:default>
<i id="image_dialog" class="dialog_left_icon dialog_left_icon_confirm icon-check-circle"/>
</j2:default>
</j2:switch>
</td>
<td>
<table border="0" width="100%">
<tr>
<td class="dialog_content">$[title]</td>
</tr>
<tr >
<td >
<div class="modal-footer"><span class="pull-right"><button class="btn btn-default" id="cancel_button" onclick="invokePromptCallBack('cancel')" style="min-width: 5em;" title="" type="submit">No
</button><button class="btn btn-primary" id="ok_button" onclick="invokePromptCallBack('ok')" style="min-width: 5em;" title="" type="submit">Yes
</button></span></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</g:ui_form>
Client Script on UI page:
function invokePromptCallBack(type) {
var gdw = GlideDialogWindow.get();
if (type == 'ok')
var f = gdw.getPreference('onPromptComplete');
else
var f = gdw.getPreference('onPromptCancel');
if (typeof(f) == 'function') {
try {
f.call(gdw, gdw.getPreference('oldValue'));
} catch(e) {
}
}
gdw.destroy();
return false;
}
var gdw = GlideDialogWindow.get();
var focusButton = gdw.getPreference('defaultButton');
if (focusButton == null)
focusButton = 'cancel_button';
gel(focusButton).focus();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2024 10:23 AM
This should be doable via UI Builder. According to the product documentation:
A Confirm modal asks a user to confirm the component action. For example, when a user presses a delete button, the user would have to confirm the deletion of data. You can choose the confirm options from the primary and secondary button label fields, such as Yes/Cancel.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2024 10:37 AM
Hi @Slava Savitsky ,
Thank you for the response, do you know if it will work when a state field is changed? Is there another way to modify the labels and keep my current client script that's working?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 12:54 PM - edited 12-04-2024 12:55 PM
Hi @RandiReyna,
I am having a similar use-case where I want to change the text of the primary button on modal from 'ok' to 'delete'. Did you find an answer to how it can be achieved? Its implemented similar to how you did using workspace client script, i.e. `g_modal.confirmDestroy()`. Any help would be appreciated. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 01:25 PM
Hi @PallavS , no I wasn't able to change it on the workspace, but I was able to in classic UI.