bernat / best_in_place

A RESTful unobtrusive jQuery Inplace-Editor and a helper as a Rails Gem
http://blog.bernatfarrero.com/in-place-editing-with-javascript-jquery-and-rails-3/
1.2k stars 571 forks source link

confirmation dialogs #525

Open inestyne opened 8 years ago

inestyne commented 8 years ago

Some of the text fields and selects i'm using this on need to be confirmed when they are changed. Is there any way to do that with options or added script?

I've started capturing mousedown events, but this doesn't seem like the correct approach:

  $(document).on("mousedown", "span[data-bip-attribute='user_type_id'] select", function (event) {
    if(confirm('Are you sure?'))
    {
      return;
    }
    event.preventDefault();
    return false;
  });
inestyne commented 8 years ago

To clarify, this is what i've come up with and i'm looking for a more appropriate way of expressing it.

  $(document).bind("ajaxSend", function(event, xhr, options){
    if (options.data.indexOf('user[user_type_id]') > 0)
    {
      if(!confirm('Are you want to change this client?'))
      {
        xhr.abort();
      }
    }
  });