Search code examples
javascriptjqueryedit-in-place

edit-in-place jquery


I use edit-in-place plugin: http://arashkarimzadeh.com/jquery/7-editable-jquery-plugin.html

I't works Great! I just need something to check if the new text is empty. If it is we have to go back and show some error alert.

The code:

        $('.name').editable({ 
         submit:'Gem',         
         cancel:'Fortryd',         
         onSubmit: function(content){ 
             $.post('/admin/ajax/products/edit_category/',{ category_name:$(this).text(),category_id: this.parent().attr('id') })
          }
     });

Can someone please help me! :-/


Solution

  • check the content.current property in the onSubmit function before posting.
    (there's also a content.previous property that can be used to check for changes)

    Example:

    $(document).ready(function() {
      $("#div1").editable({
        type      : 'textarea',
        submit    : 'OK',
        cancel    : 'Cancel',
        onSubmit : function(content) {
          alert(content.current+':'+content.previous);
        }
      });
    });