Prevent hiding of modal when clicking outside

10 views
Skip to first unread message

Matthew Crider

unread,
Jun 14, 2016, 11:33:46 AM6/14/16
to apostrophenow
We're finding it frustrating that when you click outside of a modal (i.e. in the .apos-modal-blackout) the modal closes without saving the changes.  Is there any way to disable this?  I tried something like

$( '.apos-modal-blackout' ).on({
 
'click': function(e) {
    e
.stopImmediatePropagation();
 
}
});

.. But it works once then seems to be unbound afterwards.  Also tried overriding the click.aposModal event to no avail.  Any obvious ideas from anyone?

- Matt

Tom Boutell

unread,
Jun 14, 2016, 12:03:09 PM6/14/16
to apostr...@googlegroups.com
This is how apostrophe-snippets editing modals handle that issue, when calling apos.modalFromTemplate:

        beforeCancel: function(callback) {
          if (confirm('Are you sure you want to discard this ' + options.instanceLabel.toLowerCase() + '?')) {
            return callback(null);
          }
          return callback('notconfirmed');
        },

You can use the same technique.


--
You received this message because you are subscribed to the Google Groups "apostrophenow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apostropheno...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


THOMAS BOUTELL, SUPPORT LEAD
P'UNK AVENUE | (215) 755-1330  |  punkave.com

Matthew Crider

unread,
Jun 14, 2016, 12:31:43 PM6/14/16
to apostrophenow
Sorry, bit confused how to use that.  What would I override with that beforeCancel function (its been a couple months since i've been in Apostrophe-land, forgetting some of the advanced techniques!)  

Tom Boutell

unread,
Jun 14, 2016, 1:01:21 PM6/14/16
to apostr...@googlegroups.com
Well, I really don't know what you're doing — making an entirely new apostrophe modal, or fighting with one of ours.

Matthew Crider

unread,
Jun 14, 2016, 1:03:40 PM6/14/16
to apostrophenow
I'm fighting with your schema-widget modals :)  Do I create a lib/modules/apostrophe-schema-widget/index.js file and put the overrides in there?

Matthew Crider

unread,
Jun 15, 2016, 11:39:11 AM6/15/16
to apostrophenow
I just copied apostrophe-schema-widgets's public/js/editor.js file into my project's lib/modules/apostrophe-schema-widgets/public/js/ folder and added the beforeCancel method.  Couldn't figure out a way to override the main module's editor.js without removing all the other methods..  This works but obviously is not good if the module's editor.js is upgraded.

Tom Boutell

unread,
Jun 15, 2016, 11:47:51 AM6/15/16
to apostr...@googlegroups.com
This ought to subclass it properly, substituting your own widgetTypeName of course:

var superEditor = apos.widgetTypes.widgetTypeName.editor;

apos.widgetTypes.widgetTypeName.editor = function(options) {
  var self = this;
  superEditor(self);
  self.beforeCancel = ... whatever you'd like ...;
};

Matthew Crider

unread,
Jun 15, 2016, 12:03:49 PM6/15/16
to apostrophenow
Close, I had to use superEditor.call(self, options).  Here's my entire lib/modules/apostrophe-schema-widgets/public/js/editor.js in case it helps anyone else:

$(function() {
  _
.each(apos.data.schemaWidgets, function(info) {
   
var superEditor = apos.widgetTypes[info.name].editor;


    apos
.widgetTypes[info.name].editor = function(options) {
     
var self = this;
      superEditor
.call(self, options);
     
self.beforeCancel = function(callback) {
       
if (confirm('Are you sure you want to discard your changes?')) {

         
return callback(null);
       
}
       
return callback('notconfirmed');
     
}

   
};
 
});
});

Tom Boutell

unread,
Jun 15, 2016, 12:16:03 PM6/15/16
to apostr...@googlegroups.com
Oops, yes, thanks.

Because we follow the self pattern this is the one and only time we ever have to type "this" or use "call" (:

In 0.6 we use Moog which takes all that to another level and makes subclassing very consistent throughout the system.
Reply all
Reply to author
Forward
0 new messages