1

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! :-/

william
  • 606
  • 3
  • 14
  • 29

3 Answers3

2

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);
    }
  });
});
manji
  • 47,442
  • 5
  • 96
  • 103
0

Change your onSubmit:

  onSubmit: function(content){
       if ($(this).val()=='') {
         alert("can't be blank");
        } else {
            $.post('/admin/ajax/products/edit_category/',{ category_name:$(this).text(),category_id: this.parent().attr('id') });      
        }
    }
Slee
  • 27,498
  • 52
  • 145
  • 243
0

I found a Solution:

 function end(content){
        if (content.current == '') {                 
              $(this).text(content.previous);
          }else{
              $.post('/admin/ajax/products/edit_category/',{ category_name:$(this).text(),category_id: this.parent().attr('id')});   
          }            
      }

Its works, and goes to show the previous data

william
  • 606
  • 3
  • 14
  • 29