6

I'm in struggle trying to prevent native click inside jquery datepicker.onSelect event

Example below is not working, click still is being triggered:

onSelect: function(dateText, inst) { 

if (myCondition) {
   return false; 
 }}

Another trick would be calling event.preventDefault/ inside onSelect, if event object has been available.

Any known solutions ?

senpai
  • 111
  • 2
  • 4
  • 1
    preventDefault is the right solution.. What exactly are you trying to find? – Teja Kantamneni Dec 28 '10 at 19:41
  • I have no idea how to access event object inside onSelect – senpai Dec 28 '10 at 19:48
  • By prevent "click" you mean prevent populating the selected date to get populated to the input field that Datepicker is attached to? – ifaour Dec 28 '10 at 21:03
  • Not exactly, by default Datepicker "dates" are being highlighted onClick, I just want adllow/prevent highlighting on my custom condition inside Datepicker.onSelect Sure, I could bind some "independent" onclick handler "outside Datepicker namespace", but it would be some ugly solution - an unnecessary dependency. – senpai Dec 29 '10 at 10:15

2 Answers2

1

Perhaps you can achieve this via CSS instead of binding to events?

Teddy
  • 18,357
  • 2
  • 30
  • 42
1

What if you used the beforeShow event ? as referenced here http://jqueryui.com/demos/datepicker/#event-beforeShow

This way, you could really prevent the datepicker from being displayed.

Regards,

Max

JMax
  • 26,109
  • 12
  • 69
  • 88