views:

138

answers:

3

I want to disable autocomplete for all inputs using jquery ui datepicker without doing this to every input manually. How could be this done?

A: 

Try this:

<input type="text" name="field1" value="" autocomplete="off" />
Makram Saleh
I don't want to write this to every input manually
Ibrahim Hussein
+1  A: 

Assign a css class to your datepickers, i.e. "datepicker", then do the following:

$(".datepicker").attr("autocomplete", "off");
GenericTypeTea
This doesn't work for inputs in ajax loaded forms
Ibrahim Hussein
Why doesn't it?
GenericTypeTea
I am putting this code in my main layout, i think it's being executed on current inputs in the DOM. When loading an ajax form the newly created inputs still has autocomplete on.
Ibrahim Hussein
Recall the code above after your AJAX load then?
GenericTypeTea
A: 

try this:

$(".datepicker").live( 'focus' , function() { 
$(this).attr("autocomplete", "off");
});

UPDATE:

$('.datepicker').live('click', function(e) {
  e.preventDefault();
  $(this).attr("autocomplete", "off");  
});

in anycase you have not mentioned in your question that this is coming from an ajax call!

aSeptik
For some reason this code works only after first focus for the input.I changed 'focus' to 'hover' and it works.Thanks
Ibrahim Hussein
try the updated code! and let me know! ;-)
aSeptik