AnanthaKN / jquery-in-place-editor

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

enter key not working for textareas to pass to the next line #58

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. When setting field_type: "textarea" the "Enter key" triggers the save.

What is the expected output? What do you see instead?
- In a textarea the enter key is the only way to pass to the next line
witch is not possible here. The save command should be deactivate in case
of field_type: "textarea".

In addition, when we pass to the next line the result should show this (so
- "\n" should be converted into "<br/>" in the result)

What version of the product are you using? On what operating system?
I am using version 2.1.1/ firefox/ linux (ubuntu 8.4)

Please provide any additional information below.

I solved the problem changing some lines in the code...
in the connectEventsToEditor: function() line 291 and 298
I change as following

// workaround for firefox bug where it won't submit on enter if no button
is shown
            if ($.browser.mozilla) {
                form.keyup(function(event) {
                    if (13 === event.which)
                        saveEditorAction();
                });
            }
        }

        // allow canceling with escape
        form.keyup(function(event) {
        if (27 === event.which) // escape
          return cancelEditorAction();
        else if (13 === event.which) // return (webkit and chrome nightlies
don't commit otherwise?
          return saveEditorAction();
      });

to 

// workaround for firefox bug where it won't submit on enter if no button
is shown
            if ($.browser.mozilla && "textarea" != this.settings.field_type) {
//added prevent the enter key to save for textareas
                form.keyup(function(event) {
                    if (13 === event.which)
                        saveEditorAction();
                });
            }
        }

        // allow canceling with escape
        if ("textarea" != this.settings.field_type) { //added prevent the enter
key to save for textareas
      form.keyup(function(event) {
        if (27 === event.which) // escape
          return cancelEditorAction();
        else if (13 === event.which) // return (webkit and chrome nightlies
don't commit otherwise?
          return saveEditorAction();
      });
        }
        else {
            form.keyup(function(event) {
        if (27 === event.which) // escape
          return cancelEditorAction();
      });
    }

And on handleSaveEditor: function() 

I replace 

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

to 
  var enteredText = this.dom.find(':input').val();
  //added for textareas
  var nl2br=new RegExp("\n", "g");
  enteredText = enteredText.replace(nl2br, "\n<br/>");

Original issue reported on code.google.com by adriendu...@gmail.com on 20 May 2010 at 8:50

GoogleCodeExporter commented 8 years ago
Thanks for the find, I completely missed the fact that of course I can't 
trigger commit with enter when 
showing the textarea.

As for the nl2br - I'm not so sure I want that in the inline editor propper. 
I've added a much expanded 
callback interface on trunk, could you give it a try and see if that allows you 
to workaround the br problem 
without changes to the editor itself?

Thinking about the nl2br thing more, that might make a sensible default choice 
that can then be disabled with 
a setting. I'd love to get more input from you on that one.

Original comment by mhaec...@gmail.com on 22 May 2010 at 3:19

GoogleCodeExporter commented 8 years ago
I've added a fix to the enter key in the textarea to trunk in r121, please feel 
free to reopen this issue if that 
doesn't fix the problem of newlines accidentally triggering the reload

Original comment by mhaec...@gmail.com on 22 May 2010 at 4:21

GoogleCodeExporter commented 8 years ago
I'll check on monday when I'll be back to the office. I'll download the trunk 
version
via svn.

Original comment by adriendu...@gmail.com on 22 May 2010 at 10:38

GoogleCodeExporter commented 8 years ago
ok it works in the trunk version. 

and I can add myself the nl2br doing 

jQuery(document).ready(function(){
  jQuery(".editable").editInPlace({
    saving_animation_color: "#ECF2F8",
    field_type: "textarea",
    textarea_rows: "2",
    textarea_cols: "15",
    callback: function(idOfEditor, enteredText, orinalHTMLContent, settingsParams,
animationCallbacks) {
      var nl2br=new RegExp("\n", "g");
      return enteredText.replace(nl2br, "\n<br/>");
    }
  });
});

It works fine. Now I don't know if this should be changed by default.

Original comment by adriendu...@gmail.com on 25 May 2010 at 1:50