views:

65

answers:

2

I am using jQuery UI and trying to disable all text boxes in a data group, but only do so once per loading of the tabs. Here is what I have so far:

$(function () {
        $("#tabs").tabs({
            cache: true,
            load: function (event, ui) {
                $(".data-group").one('load', function () {
                    $(this).find(':text').attr('disabled', 'disabled');
                });
            },
            select: function (event, ui) {
                // Do Stuff
            }
        });
    });

The result is that I can enable the text boxes (via the interface), enter data, but the when I switch away from the tab and switch back, the value is in the text box (and validation messages are shown if there is an error in the data), but all boxes are disabled.

Suggestions for fixing this?

A: 

Try binding to the show event, something along the lines of 'if there is data in at least one of the text inputs then enable them', e.g.:

show: function(event, ui) {
    if($(".data-group").find(":text[value]").length) {
        $(".data-group").find(":text").removeAttr("disabled");
    }
}
karim79
This does work, but it seems that it would be more efficient to have the disabling only happen once per change of tab. Is that possible? If not, I will go with your method.
JasCav
Actually I realized this won't work because a user could enter a value and then disable the checkbox. Again, still seems like there should be a more efficient answer. I do appreciate your help.
JasCav
A: 

I ended up solving this by caching the tabs so they only load once. Then, I enable the appropriate text boxes. From that point on, the user's actions determine if other boxes are enabled or disabled.

JasCav