Using the YUI 3 Calendar Date Selector from Alloy
June 18, 2010 at 10:46 am by Eric Miraglia | In Development, YUI 3 Gallery | 6 CommentsThe Alloy components (contributed by Nate Cavanaugh and Eduardo Lundgren from Liferay) in the YUI 3 Gallery are simple to use. This example illustrates the use of the Alloy calendar to progressively enhance a set of select elements for date selection.
Let’s start with the markup — the HTML that will be on the page and functioning regardless of whether JavaScript is enabled. Alloy’s Calendar module does not require this markup; you can feed it an empty element and it will create the select elements for you in the event that your use case would not benefit from progressive enhancement.
<div id="calendar">
<select class="yui3-datepicker-month" name="month" id="monthselect">
<option value="0">
January
</option>
<option value="1">
February
</option>
...
</select>
<select class="yui3-datepicker-day" name="day" id="dayselect">
<option value="1">
1
</option>
<option value="2">
2
</option>
...
</select>
<select class="yui3-datepicker-year" name="year" id="yearselect">
<option value="2009">
2009
</option>
...
</select>
</div>
With this markup in place (or with just an empty root element if we aren’t progressively enhancing existing form fields), we bring in the Alloy Calendar module with datepicker selection support from the YUI 3 Gallery. This requires us to have YUI 3 on the page and then to follow the configuration step outlined on the module’s Gallery page.
<script src="http://yui.yahooapis.com/3.1.1/build/yui/yui-min.js"></script>
<script>
YUI({
// All of this configuration information can be cut-and-pasted from the Gallery entry for
// this module: http://yuilibrary.com/gallery/show/aui-calendar-datepicker-select
gallery: 'gallery-2010.06.07-17-52',
modules: {
'gallery-aui-skin-base': {
fullpath: 'http://yui.yahooapis.com/gallery-2010.06.07-17-52/build/gallery-aui-skin-base/css/
gallery-aui-skin-base-min.css',
type: 'css'
},
'gallery-aui-skin-classic': {
fullpath: 'http://yui.yahooapis.com/gallery-2010.06.07-17-52/build/
gallery-aui-skin-classic/css/
gallery-aui-skin-classic-min.css',
type: 'css',
requires: ['gallery-aui-skin-base']
}
}
}).use('gallery-aui-calendar-datepicker-select', function(Y) {
var datePickerSelect = new Y.DatePickerSelect({
displayBoundingBox: '#calendar',
dateFormat: '%m/%d/%y',
yearRange: [ 2009, 2012 ],
dayField: Y.one("#dayselect"),
dayFieldName: "day",
monthField: Y.one("#monthselect"),
monthFieldName: "month",
yearField: Y.one("#yearselect"),
yearFieldName: "year"
}).render();
});
</script>
Here’s a live version of this simple example.
It’s as simple as that. The configuration properties for datePickerSelect are lucidly defined in the Alloy documentation. In this example, the properties are used to set the root element, format the date, set the date range, and then wire up our existing select elements to the widget instance so that it knows which form fields to use for progressive enhancement. In practice, only the root element (displayBondingBox) is a required property.
Check out the YUI 3 Gallery roster for a full list of the Alloy UI contributions.
Share and extend: Bookmark with del.icio.us | digg it! | reddit!
6 Comments
Sorry, the comment form is closed at this time.

Copyright © 2006-2012 Yahoo! Inc. All rights reserved. Privacy Policy - Terms of Service
Powered by WordPress on Yahoo! Web Hosting.


Hey Eric, nice post :)
If you want you could use populateDay, populateMonth and populateYear options to save some html from the markups.
http://alloy.liferay.com/deploy/api/DatePickerSelect.html#config_populateDay
Comment by Eduardo Lundgren — June 18, 2010 #
Thanks, Eduardo.
Comment by Eric Miraglia — June 18, 2010 #
http://www.uedmagazine.com/cubee/src/calendar/demo/calendar.html
see this
Comment by jayli — June 20, 2010 #
the css that gets pulled in seems to set some pretty broad styles (including the body tag). is there any way to use the allow components without pulling in all the css? (like styles only for the component we’re using)
Comment by bholub — July 21, 2010 #
The base styles need to be adjusted since they do affect far more than just the widget itself. Is there a way to deploy the widget without the base stylesheet?
Comment by Aramys Miranda — November 17, 2010 #
Hi guys, you can remove the css modules from the config that gets passed in, and that should prevent the global css module from being loaded.
The down side, of course, is that you lose out on the shared styling that’s needed (such as the reset, which is the styling you probably don’t want).
One other option is to also use the “insertBefore” config param to specify the id of a link element that you wish to have come after all of the css so that it will take precedence.
This way your css won’t be clobbered by css loaded after the page (I haven’t personally tested this option, but according to Adam, it should work like this I think :).
We still have some improvements to do regarding the styling to modularize it a bit more and use the reset only on “skinned” elements, so any input you guys can provide, either via email or the forum is greatly appreciated :)
Thanks guys,
Comment by Nate Cavanaugh — November 18, 2010 #