views:

458

answers:

2

Hello, this is my first time using JS, so i really have no idea what i am doing.

I have a table with data, and using jEditable to allow a user to edit the data and POST it to my php script. When user hits "Save", it opens jQuery UI with the data from php script and it seems to work fine, however, if the user hits Cancel or Esc to close the jQuery UI dialog, they and up back on the page, but the cell they tried to edit is now completely empty. How do i get the cell re-populated?

Thank you!

$(".editable_textarea").editable("/path/to/my/script.php", {
    indicator : "<img src='/images/indicator.gif'>",
    type   : 'textarea',
    submitdata: { _method: "post", uri: "<?php echo $this->uri->segment(3); ?>" },
    select : false,
    submit : 'Save',
    cancel : 'Cancel',
    tooltip   : "Click to edit...",
    cssclass : "editable",
    onblur: "cancel",
    cssclass: "edit_destination",
    callback: 
       function(value, settings) {
          $(this).dialog({
              autoOpen: true,
              width: 400,
              modal: true,
              position: "center",
              resizable: false,
              draggable: false,
              title: "Pending Changes",
              buttons: {
                  "Cancel": function() {
                      $(this).dialog("close"); },
                  "Confirm Changes": function() {
                      document.findSameDestination.submit(); }
              }

          });

          $('form#findSameDestination').submit(function(){
              $(this).dialog('open');
              return false;
          });

        $(this).editable("disable");
   },
   data: 
      function(value, settings) {
          var retval = value.replace(/<br[\s\/]?>/gi, '\n');
          retval = retval.replace(/(<([^>]+)>)/gi, '');
          return retval;
      }
   });

Still no idea how to fix this and I dont have enough points to offer a bounty...

+1  A: 

I may not be right but it may be the cancel event you're calling with onblur. Try changing the

onblur: "cancel"

to

onblur: "function(e){;}"

which will essentially do nothing. If i got the jEditable code right, it reverts the input value to the original one upon onblur event, which in turn is called when clicking the Cancel button. Still, I might be wrong - it's 2 am at my place :)

dare2be
dare2be, thanks for the reply. The onblur: part is takend directly from jEditable documentation:"@param String options[onblur] 'cancel', 'submit', 'ignore' or function ??"and that part is working well. when i click out of the jEditable textarea, it changes back to contents of the table cell before the edit (even though it ads a newline at the bottom for some strange reason).The part that does not restore the text, is when i cancel the jQuery UI dialog. It appears to me, and correct me if i am wrong, that i seen some king of Ajax function somewhere in the middle?
solefald
Sorry, I must have misunderstood you. However, that makes your problem even weirder. I'm lost - will look into it tomorrow.
dare2be
Hey! Have you wrapped the place where you call $(".editable_textarea").editable("/path/to/my/script.php", {...}); with $(document).ready(function() {...});? Because the script works perfectly fine (i.e. the 'cancel' button reverts to the original) for me if I do wrap it this way!
dare2be
A: 

Can you call the blur event in the cancel event of the dialog?

Cancel": function() {
                      document.editable_textarea.blur();
                      $(this).dialog("close");

It doesn't seem like the cancel event for the jEditable is being called when the dialog is closed.

jen
Thank you Jen, but this does not work :( If I add that, Cancel button does not do anything at all, and on Escape, I am still presented with an empty table cell...
solefald
How about: document.editable("cancel");
jen
same result again :(
solefald