edit-in-place jquery

1.1k views Asked by At

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

3

There are 3 answers

0
manji On BEST ANSWER

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);
    }
  });
});
0
Slee On

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') });      
        }
    }
0
william On

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