flaplante (5) [Avatar] Offline
#1
I have been using the enable/disable functions described on p.12-13 of the first edition for months now with great success. But I am now getting complaints from IE8 users. Is this a known problem and is there any work around available at this time? I can find nothing about it at the jQuery site.

Fred LaPlante
bear.bibeault (675) [Avatar] Offline
#2
Re: enable/disable (p.12-13) and IE 8
Hey Fred,

I haven't heard anything about IE8, and I haven't used it myself.

Could you get more info on exactly what's happening?

bear
flaplante (5) [Avatar] Offline
#3
Re: enable/disable (p.12-13) and IE 8
Don't use it much myself if I can avoid it. But users of a some open source software I'm involved in do.

I have a form with various input fields and a 'submit' buttom. At startup, I disable the button so user can't send a blank form. So far so good, and button goes gray and ineffective as it should. I have bound to all the input fields a function that, among other things, call a function 'exactly' like what you have in your book to enable the button. That fails, but only with IE, with a message: "Object doesn't support this property or method" and points to the disable call. Interestingly, Firefox, Safari, Chrome all handle this just fine.

Fred LaPlante
bear.bibeault (675) [Avatar] Offline
#4
Re: enable/disable (p.12-13) and IE 8
Does it work in IE7?

And can you include the exact code that's failing?

I'm not sure I can be of help at this point, but will give it my best shot.
flaplante (5) [Avatar] Offline
#5
Re: enable/disable (p.12-13) and IE 8
Sure and thanks for the interest.

//------------------------------------------------------------------------------
// jQuery plugins for lookup
// element enable/disable - 'jQuery in Action', p12, 22Aug2008 - fl
$.fn.disable = function () {
return this.each(function () {
if (typeof this.disabled != "undefined)") this.disabled = true;
});
};
$.fn.enable = function () {
return this.each(function () {
if (typeof this.disabled != "undefined)") this.disabled = false;
});
};
........
lkup = {
....
init: function () {
....
lkup.srchBtn = $('#srchBtn');
lkup.resetForm();
lkup.srchBtn.bind('click',null,lkup.doSearch);

$('.criteria').bind('change',null,lkup.enableSrchBtn);
....
},
resetForm: function () {
....
lkup.disableSrchBtn();
....
},

disableSrchBtn: function () {
....
lkup.srchBtn.disable();
},
enableSrchBtn: function () {
....
lkup.srchBtn.enable();
},
....
}
//------------------------------------------------------------------------------
As mentioned, the disable of the button works fine on startup. But when input fields with class="criteria" are entered (changed?) and focus changed by use of tab key or mouse, the enable function fails and the button is not enabled.

And no I haven't tried IE7, I don't have a copy installed anywhere anymore. Bad idea for developers I suppose, but I never have bothered to keep older versions of code around.

Fred LaPlante
bear.bibeault (675) [Avatar] Offline
#6
Re: enable/disable (p.12-13) and IE 8
Let's try changing up the disable/enable code to use the attributes rather than the properties:
E.g.
$(this).attr('disabled',false)

and see if IE8 likes that better.
flaplante (5) [Avatar] Offline
#7
Re: enable/disable (p.12-13) and IE 8
Bear,

changed functions to:
$.fn.disable = function () {
return this.each(function () {
//if (typeof this.disabled != "undefined)") this.disabled = true;
if (typeof this.disabled != "undefined)") $(this).attr('disabled',true);
});
};
$.fn.enable = function () {
return this.each(function () {
//if (typeof this.disabled != "undefined)") this.disabled = false;
if (typeof this.disabled != "undefined)") $(this).attr('disabled',false);
});
};

No luck, Button is not enabled when input fields are changed. But button does get disabled at startup.

Get error msg from IE8 at startup:
"Error: Object doesn't support this property or method"
with pointer to thie line: "lkup.srchBtn.disable();"

incidently the HTML for the button is:
<input type="button" id="srchBtn" name="srchBtn" value="Search" class="button" />

Fred
bear.bibeault (675) [Avatar] Offline
#8
Re: enable/disable (p.12-13) and IE 8
What is srchBtn in this line:

lkup.srchBtn.disable();
flaplante (5) [Avatar] Offline
#9
Re: enable/disable (p.12-13) and IE 8
lkup.srchBtn = $('#srchBtn');

Its defined in the lkup.init() function in the earlier paetial listing I sent. It refers to the input statement shown in my lasrt email.

Fred