hasClass test for hasDatepicker failing - why?

hasClass test for hasDatepicker failing - why?

Hi everyone,

 

I have a form where all date entry fields have had the datepicker attached using the following code:

 

$(this).datepicker({

   changeMonth: true,

   changeYear: true,

   dateFormat: jqDateFormat,

   showOn: jqDateAction,

   buttonImage: imagesPath+"calendar-datepicker.png",

   buttonImageOnly: true,

    onClose: function(datesel,elem2) {SetEntryFlag(this.id);}

});

 

jqDateFormat = “ddmmy”, jqDateAction = “button”

 

I have a JavaScript function later where I need to check to see if a form field has a datepicker attached and if so activate it,

 

The test I am using is:

 

if ($('#'+jqfieldN).hasClass('hasDatepicker')) {….}

 

jqfieldN is the field id, e.g. IO-DATE-PROMISE.0 (modified to allow for the period so… IO-DATE-PROMISE\\.0).

 

jQuery IS finding the field with as I can display the current field value but the test hasClass for ‘hasDatepicker’ is failing and I don’t know why.

 

I have another function elsewhere that does the same test but using the object ‘this’ and that test works. The object ‘this’ is not valid in this situation though due to the way the script is called but I still don’t know why the test would fail.

 

The field displays the datepicker icon and clicking the icon displays the datepicker correctly and it all works, so the link is on this field.

 

Does anyone know why my test is failing or can offer another method of checking to the if the form field has a datepicker already linked to it.

 

Thanks,



Doug.