-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Hi,
something which really frustrates me in FormTools 3.0.20 is the fact that by default date pickers (Date field types) have some absurd date span. So I want to share with my own solution on how to set year range in your date picker and also ask if anyone knows a better solution. My solution is not the most elegant (because it uses window.onload but works nonetheless and let's the admin set the year range of date pickers to the desired value.
My solution goes like this:
- install Custom Fields module (I tested it with version 2.1.0)
- create a copy of the
Datetype

- select the new field type, go to Settings and create a new setting for year range:

- now go to Displaying > Edit field and modify it in the following way (first few lines set correct CSS classes so code from the original
datetype won't overwrite what we set up here and the last few lines actually update the date range of the date picker to the one we will set in the settings):
{assign var=class value="fixeddate"}
{if $display_format|strpos:"datetime" === 0}
{assign var=class value="fixeddatepicker"}
{/if}
[...]
{if $comments}
<div class="cf_field_comments">{$comments}</div>
{/if}
</div>
<script>
window.onload = function(){
$( ".fixeddate" ).datepicker( "option", "yearRange", "{$yearRange}" );
$( ".fixeddatepicker" ).datepicker( "option", "yearRange", "{$yearRange}" );
};
</script>
- go to Displaying > Javascript and modify the following lines:
- replace
$(".cf_datepicker").each(function() {with$(".fixeddate").each(function() { - replace
$(".cf_datetimepicker").each(function() {with$(".fixeddatepicker").each(function() {
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels

