Continuing exploration on mixing UI and Mobile:
including the jquery-ui-1.8.6.custom.css messes up the mobile slider thumb a bit FYI
JQuery UI Datepicker
getting the UI Datepicker to work is non trivial.
Unless you are willing to spend some time on it, it's probably better to wait for the jQuery mobile datepicker which will undoubtedly work and look better (thanks to Filament)
But if you really want a datepicker, now, read on. Some of the solutions (defanging the aggressive enhance) may be appropriate when trying to integrate other plugins into mobile as well - or perhaps mobile's enhancer could be adapted a bit ;)
Anyway, here we go:
Without the button trigger (DatePicker's showOn, buttonImage, buttonImageOnly) it already works (plusminus A href comments below)
However, you don't really want a text field & focus, because at least on the iphone the keyboard comes up and covers the calendar, defeating the whole purpose of showing it.
So I use
showOn: 'button',
buttonImage: '/images/DatePicker.gif',
buttonImageOnly: true,
and I have my datepicker INPUT field disabled so the user never focuses inside it.
But when you turn on the DatePicker button like that, you run into JQ Mobiles aggressive enhance in several places. It really wants to mark up the button that is inserted by the DatePicker as a peer to your date INPUT.
It wraps it in DIVs, cuddles it in all kinds of button classes, and finally wraps the button in an A. Too much of a good thing.
Just add the data-role="none" on the datepicker button:
myDatePicker.datepicker( options )
myDatePicker.parent().find('button').attr( "data-role", "none" );
Also, the jQuery UI DatePicker (and I suspect plenty of other plugins) have some A's that don't have an href (because they use an onclick handler). For example, the next month and prev month buttons are like that.
Well mobile does not like A's without hrefs. The fix is easy:
jquery.mobile.js #3111 was
href = $this.attr( "href" ).replace( location.protocol + "//" + location.host, ""),
change to
hasHref = $this.attr( "href" );
if( !hasHref )
return; // do nothing for anchors that have no href
href = hasHref.replace( location.protocol + "//" + location.host, ""),
After all that I now have a working (if not yet superbly styled) datepicker on the iphone at least - the button that caused so much trouble is below instead of to the right of the date field in the narrow layout. I can live with that for now...(you'd have to make the text field width 80% and keep display: inline-block I think, but I am no CSS guru, so won't go there)
Oh one last thing:
the day numbers on the calendar are A's (this time WITH an href='#')
When clicked on an iphone, the hash change in the address bar causes Safaris location bar to briefly drop down, just like it does when an ajax request is made (why doesn't apple fix this, I wonder, or do they think this is a feature ? For what ?)
To solve, get rid of the href='#' (I tried live binding an onclick handler - too late, click already happened - or removing the href attr's in the DatePicker beforeShow() but doesnt work.)
So you have to hack the actual Datepicker source. Find these two lines in your datepicker js or combined ui source:
/* Generate the HTML for the current state of the date picker. */
_generateHTML: function(inst) {
and scroll down to where it makes the tbody of the calendar table (or just look for href in that function :) and shred the href:
'" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display selectable date
I tried it and that indeed prevents the "dipping address bar problem"