views:

239

answers:

3

Hey

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

A: 

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
+2  A: 

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);
    }
  });
});
najmeddine
can you show an example ?
william
A: 

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