Skip to content

Instantly share code, notes, and snippets.

@duskohu
Created July 9, 2013 09:29
Show Gist options
  • Save duskohu/5955986 to your computer and use it in GitHub Desktop.
Save duskohu/5955986 to your computer and use it in GitHub Desktop.
Nextras\Forms - DatePicker for twitter bootstrap (http://www.malot.fr/bootstrap-datetimepicker/) add input-append icons style
<?php
$form->addDatePicker('date', 'Date')
->setDefaultValue(new DateTime());
jQuery(function ($) {
$('.date, .datetime-local').each(function (i, el) {
el = $(el);
var input = false;
if (!el.parent().hasClass('date')) {
if (el.find('input[type=date]')) {
input = el.find('input[type=date]');
input.get(0).type = 'text';
input.removeClass('date');
} else {
el.get(0).type = 'text';
}
el.get(0).type = 'text';
el.datetimepicker({
startDate: el.attr('min'),
endDate: el.attr('max'),
weekStart: 1,
minView: el.is('.date') ? 'month' : 'hour',
format: el.is('.date') ? 'd. m. yyyy' : 'd. m. yyyy - hh:ii',
autoclose: true
});
if (input) {
input.attr('value') && el.datetimepicker('setValue');
} else {
el.attr('value') && el.datetimepicker('setValue');
}
}
});
});
<div id="{$form->getElementPrototype()->id}-date-pair" class="control-group">
{label date/}
<div class="controls">
<div class="input-append date">
{input date}
<span class="add-on"><i class="icon-remove"></i></span>
<span class="add-on"><i class="icon-calendar"></i></span>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment