Skip to content Skip to sidebar Skip to footer

How To Disable Certain Controls Until Update Is Successful?

I'm working with a GridView and pretty much everything is working fine. The only thing left is to make sure that when I'm typing in one text field, all other text fields and Submit

Solution 1:

Try code bellow;

$(function () {
//this is based on your code only, this could be done a lot prettier if you added a custom attribute to each// <tr> like let's say - myrownumber ... then there is no need to get a child and find rownumber on the fly, //an everything would be prettier; 
$('input').live("focus", function () {

    var rowId = $(this).attr('id');
    var selectedRow = rowId.substring((rowId.length - 1), rowId.length);
    $('tr').each(function () {
        //find rownum var inputId = $(this).find('input').attr('id');

        if (inputId != null && typeof inputId !== "undefined") {
            var row = inputId.substring((inputId.length - 1), inputId.length);

            if (row !== selectedRow) {
                $(this).find('input').prop("disabled", true);
            }
        }
    });

});
//once again this is based on your code, this can be done more ellegantly if you implement smarter naming //make all buttons of same class, etc... for easier selection
$('input[type=submit]').live("click", function () {
    //submit your request and get response //if response success 
    $('tr').each(function () {
        $(this).find('input').prop("disabled", false);
    });

});

});

Solution 2:

With the help of @user3380971 I have finalized my solution to the problem:

$(function(){

$('input[type="text"]').live("focus", function() {
    var rowId = $(this).attr('id');
    $('tr').each(function(){
        var inputId = $(this).find('input[type="text"]').attr('id');
        var submitId = $(this).closest("tr").find('input[type="submit"]').attr('id');
        alert(submitId);
        if(inputId != null && typeof inputId != "undefined"){
            if(rowId != inputId){               
                $(this).find('input[type="text"]').attr("disabled", "disabled");
                $(this).closest("tr").find('input[type="submit"]').attr("disabled","disabled");
            }
        }
    });                                
});

});

Now, I'm disabling text fields and buttons belonging to different rows then onces that belong to the row under update

Post a Comment for "How To Disable Certain Controls Until Update Is Successful?"