- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2016 04:14 PM
I have a UI page which I am calling from a client script. The Ui page has 2 buttons Yes and No.
I am calling the UI page from GlideDialogWindow.
I want the to know if the user selected Yes or No.
Ui page (pop_up_yes_no):
<g:ui_form>
<button id="confirmYes" onClick = "getYes()" type ="button">Yes</button>
<button id="confirmNo" onClick = "getNo()" type ="button">No</button>
</g:ui_form>
GlideDialogWindow in client script
var gdw = new GlideDialogWindow('pop_up_yes_no', callbackFunct);
gdw.setTitle('Configuration Item');
gdw.setSize(750,300);
gdw.render();
}
How can get which one user (Yes or No) selected and use them in the call back funtion to set some values on the form ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2016 04:41 PM
You need to bind the responses to yes and no functions:
//UI action
function checkCancel() {
var cancelIt= function(){
//probably do nothing here?
};
var doIt= function(){
//do something here
};
function popMessage() {
var gdw = new GlideDialogWindow('pop_up_yes_no');
gdw .setTitle('Configuration Item');
gdw .setPreference('onYes', cancelIt.bind(this));
gdw .setPreference('onNo', doIt.bind(this));
gdw.setSize(750,300);
gdw .render();
}
}
//UI page
//HTML
<td class="dialog_buttons">
<g:dialog_button id="yes" type="button" onclick="invokePromptCallBack('yes');">Yes</g:dialog_button>
<g:dialog_button id="no" type="button" onclick="invokePromptCallBack('no');">No</g:dialog_button>
</td>
//Client script
function invokePromptCallBack(type) {
var gdw = GlideDialogWindow.get();
if (type == 'yes')
var f = gdw.getPreference('onYes');
else
var f = gdw.getPreference('onNo');
if (typeof(f) == 'function') {
try {
f.call(gdw, gdw.getPreference('oldValue'));
} catch(e) {
}
}
gdw.destroy();
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2016 04:41 PM
You need to bind the responses to yes and no functions:
//UI action
function checkCancel() {
var cancelIt= function(){
//probably do nothing here?
};
var doIt= function(){
//do something here
};
function popMessage() {
var gdw = new GlideDialogWindow('pop_up_yes_no');
gdw .setTitle('Configuration Item');
gdw .setPreference('onYes', cancelIt.bind(this));
gdw .setPreference('onNo', doIt.bind(this));
gdw.setSize(750,300);
gdw .render();
}
}
//UI page
//HTML
<td class="dialog_buttons">
<g:dialog_button id="yes" type="button" onclick="invokePromptCallBack('yes');">Yes</g:dialog_button>
<g:dialog_button id="no" type="button" onclick="invokePromptCallBack('no');">No</g:dialog_button>
</td>
//Client script
function invokePromptCallBack(type) {
var gdw = GlideDialogWindow.get();
if (type == 'yes')
var f = gdw.getPreference('onYes');
else
var f = gdw.getPreference('onNo');
if (typeof(f) == 'function') {
try {
f.call(gdw, gdw.getPreference('oldValue'));
} catch(e) {
}
}
gdw.destroy();
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2016 08:49 AM
Thanks Stephan.
2 questions: The client script is as a part of the UI page right. And what is oldValue in the "f.call(gdw, gdw.getPreference('oldValue'))". And I am not writing a UI action but a client script to call the UI page and how is the action returned to the client script (where the glideWIndow is called)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2016 07:40 AM
Yes, the client script is part of the UI page.
That's a great question. The first parameter is the context(this), the second is a parameter you can provide to your callback function. So if you added that parm to the gdw, it would be available to your callback.
I grabbed that line from another UI policy without thinking about it but other examples use a field value or nothing:
function invokePromptCallBack(type) {
var gdw = GlideDialogWindow.get();
if (type == 'ok')
var f = gdw.getPreference('onPromptClose');
if (typeof(f) == 'function') {
try {
f.call(gdw);
//or
//f.call(gdw, gel('glide_prompt_answer').value);
} catch(e) {
}
}
gdw.destroy();
return false;
}
"How is the action returned to the client script": The action never leaves the client script. UI pages are called non-modally. Meaning, when the browser executes "gdw.render()" it doesn't stop and wait for it to return. It will continue running whatever follows in that script.
This is why we use a callback. Anything else you want to accomplish when that form finishes should be in that callback or called by the callback.
Alert is an example of a modal popup.
GlideDialogWindow is non-modal (throw an alert after the "gdw.render()" and you'll see the alert pop up first)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2016 09:20 AM
I think I got it. Thans Stephan