0

I have a simple grid layout I wrote using jQuery. I have one problem. I want to allow only one edit row at a time. So I keep track of current editing row and reset it on next edit button is clicked. Still when I click edit for next time it allows me edit. completeEdit works fine cause I am also calling it from cancel button by passing current row.

 var currentRowEdit =null;

   $(tableid + ".edit").live('click', function(event) {
            currentRowEdit = $(this).parent().parent();
            editRow(currentRowEdit);
    });


function editRow(row){
        if(currentRowEdit!=null){
            completeEdit(currentRowEdit);               
        }              
           $(row).find(".save").show();
           $(row).find(".cancel").show();
           $(row).find(".edit").hide();

    }

function completeEdit(row){             
         $(row).find(".save").hide();
          $(row).find(".cancel").hide();
         $(row).find(".edit").show();              
    }

2 Answers 2

1
function completeEdit(row){
   $(row).find(".save").hide();
   $(row).find(".cancel").hide();
   $(row).find(".edit").show();   
   currentRowEdit = null; // reset the currentRowEdit
}

According to comment

Your code is not hiding the the .save and .cancel button. Because, if you look at you code flow will notice, after the completeEdit() function you're using .show() method for those button.

As a result, your buttons hide when completeEdit() done but after that when rest of the code of editRow() executed, then those buttons again become visible.

Sign up to request clarification or add additional context in comments.

1 Comment

@SoneshDabhi please check the update and hope you will find clues.
0

I believe you are calling completeEdit and editRow on same row. you should call completeEdit on previous and editRow on new

 var currentRowEdit =null;

   $(tableid + ".edit").live('click', function(event) {
            completeEdit(currentRowEdit);
            currentRowEdit = $(this).parent().parent();
            editRow(currentRowEdit);
    });


function editRow(row){



           $(row).find(".save").show();
           $(row).find(".cancel").show();
           $(row).find(".edit").hide();

    }

function completeEdit(row){
         if(row==null){
           return;

        }
         $(row).find(".save").hide();
          $(row).find(".cancel").hide();
         $(row).find(".edit").show();    

    }

1 Comment

Thanks . I made that change . But still the problem remains .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.