AnanthaKN / jquery-in-place-editor

Automatically exported from code.google.com/p/jquery-in-place-editor
Other
0 stars 0 forks source link

[Change] cancel button and escape key event handling #67

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Set show_buttons = true
2. Create delegate:didCloseEditInPlace and delegate:shouldCloseEditInPlace 
functions
3. Attempt to determine if a "cancel" or a "save" has occurred inside the 
delegates

What is the expected output? What do you see instead?
An event should be passed to the delegates
No events are sent to the delegate

What version of the product are you using? On what operating system?
2.2.0

Please provide any additional information below.

I applied a couple of patches to the code - 

---- send the triggering event to the didCloseEditInPlace delegate ----
this required the event to be passed to the reinit function.  The argument is 
optional, hence the first line in the patch sets it to false if it isn't passed.

I then added the event object as an argument when the reinit() function is 
called in the handleCancelEditor function

By passing the event into the reinit function (and thus the didCloseEditInPlace 
delegate) I can then determine if the form was closed from a cancel action 
(escape key or cancel button) and react accordingly

---- send the triggering event to the cancelEditorAction function for the 
"escape" key (form.keyUp) event ----
when using the jQuery format of $(selector).event_name(function_name), the 
triggering event is already passed to the named function.

Your implementation of the form.keyup() event does not pass the event to the 
cancelEditorAction function - so I added it

Passing the event allows me detect in the "shouldCloseEditInPlace" delegate if 
the escape key is pressed or the cancel button was pressed - thus allowing me 
to react to the different buttons

Thanks for a cool plugin - hope I was able to help.

Original issue reported on code.google.com by jtre...@gmail.com on 27 Jul 2010 at 5:11

Attachments:

GoogleCodeExporter commented 8 years ago
I add in line 377:
this.restoreOriginalValue(); 

handleCancelEditor: function(anEvent) {
        // REFACT: remove duplication between save and cancel
        this.restoreOriginalValue();  

        if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent))
            return;

        var enteredText = this.dom.find(':input').val();
        enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText);

        this.restoreOriginalValue();
        if (hasContent(enteredText) 
            && ! this.isDisabledDefaultSelectChoice())
            this.setClosedEditorContent(enteredText);
        this.reinit();
    }

Original comment by nowicki....@gmail.com on 29 Apr 2011 at 10:48

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Thanks, nowicki. Your fix gives expected behavior and keeps my UI in sync with 
my database.
-John

Original comment by johnmhol...@gmail.com on 21 Jun 2011 at 4:40

GoogleCodeExporter commented 8 years ago
Tested and working in:

* Linux - FF 10.0.1, Chrome 18.0.1025.142
* Windows XP - IE 8.0.6001.18702, FF 11

Without this fix, ESC does not work in FF 10.0.1 on Linux.

Original comment by dave.jar...@gmail.com on 14 Apr 2012 at 11:12

GoogleCodeExporter commented 8 years ago
Hi,
I just want to thank nowicki for his code.
I had the same problem and nowicki's code fixed it.

Thank you 

regards

Original comment by Andrea.W...@gmail.com on 4 Nov 2014 at 9:24