$(window).on('dialogclose', function(ctxt) {
$.each(skuid.model.list(), function(i,m){
if(!($.isEmptyObject(m.changes))){
m.cancel();
}
});
});
How could I just cancel the models which are in current popup's context. Any Idea?
Thanks!
-
1,420 Points
Posted 4 years ago
mB Pat Vachon, Champion
-
42,936 Points
Either an action framework or choose a button in the popup to trigger. The latter would be harder to do, but better for page management.
mB Pat Vachon, Champion
-
42,936 Points
Rob Hatch, Official Rep
-
44,168 Points
What we reccomend is handling the "cancel model" action when you open the popup. This is an action that can be managed with the current action framework. So for a "New Contact" button we'd build out the following actions.
1. Cancel NewContact model (to get rid of any old rows where users had hit the red x)
2. Create New Row on NewContact model
3. Open Popup.
This allows you to get the same effect, without any javascript.
mB Pat Vachon, Champion
-
42,936 Points
The recommendation covers most scenarios where issues might arise. I can't think of a specific scenario, but I'm sure it can cause problems that the model has changes to it.
-
1,420 Points
I have a skuid table which is based on model 'OpenTasks'. The skuid table has a row action 'View/Edit Details' of type 'Pop Up' which has field editor (based on the same model 'OpenTasks' of course) . When I click View/Edit Details in the UI I get nice pop up which is cool. But if I change something on the popup and close with 'x' without saving/canceling it, the model ('OpenTasks') will have unsaved changes. Which is rather confusing. I would like to get the 'OpentTasks' model ( by using javascript or any other way eg. Action framework ) so that I can cancel 'OpenTasks' model when I close the popup with 'x'. As I already mentioned I could do it with the following
$(window).on('dialogclose', function(ctxt) {
$.each(skuid.model.list(), function(i,m){
if(!($.isEmptyObject(m.changes))){
m.cancel();
}
});
});
But the problem is, it cancels all the models which have unsaved changes while the requrement is to Cancel ONLY the model on which the popup's field editor is based ('OpenTasks' model in this case).
-
3,496 Points
Moshe Karmel, Champion
-
8,646 Points
Try this, you should be able to get at the model manually (skuid.model.getModel()): https://community.skuidify.com/skuid/topics/add-a-beforeclose-event-handler-to-a-popup
mB Pat Vachon, Champion
-
42,936 Points
There must be a way to determine which component and thus model is in the popup. If that is so, then the event listener could be dynamic. We could even add something that opens a new popup that confirms the user action. Not sure about being able to cancel the close popup though.
Would be slick for sure.
-
1,420 Points
@Moshe I had a look in to the link you pointed to but it does not seem to work yet. I think this functionality is not implemented in skuid yet. Also, even if this functionality worked, it would not give me which models were used in the current popup to cancel these dynamically (which is my main concern).
@Pat Yes, there must be a way to determine which component and thus model is in the popup. I am expecting someone from skuid to provide clues.
Zach McElrath, Employee
-
49,740 Points
$(window).on('dialogclose', function(e) {
// Get the contents of our Dialog/Popup
var dialogContents = $(e.target);
// Find the first Field Editor child (this might be different depending on your structure)
dialogContents.children('.nx-basicfieldeditor').each(function(){
var el = $(this),
dataObject = el.data('object');
if (dataObject) {
var model = dataObject.model;
if (model) model.cancel();
}
});
});
mB Pat Vachon, Champion
-
42,936 Points
-
1,420 Points
The code you provided worked well ( with slight tweak: used find() method instead of children()). Also, it now cancels only the models which has unsaved changes.
$(window).on('dialogclose', function(e) {
// Get the contents of our Dialog/Popup
var dialogContents = $(e.target);
// Find the first Field Editor child (this might be different depending on your structure)
dialogContents.find('.nx-basicfieldeditor').each(function(){
var el = $(this),
dataObject = el.data('object');
if (dataObject) {
var model = dataObject.model;
if (model && !($.isEmptyObject(model.changes))) model.cancel();
}
});
});
Related Categories
-
Popups and Drawers
- 9 Conversations
- 7 Followers
-
Javascript Snippets
- 59 Conversations
- 121 Followers