Forums

datepicker FAQ

mdma 28 Aug, 2015
Hello, from the faq: which does not work for me...
1.)For example, this will set the start date to today.

data-start_date=<?php echo date("d-m-Y"); ?>


Where to put this code? Edit element settings(datepicker)->Advanced->Start Date if i put this code exactly like in the faq:
i look into firebug i see:
data-start_date="data-start_date=<?php echo date("d-m-Y"); ?>"

if i only put <?php echo date("d-m-Y"); ?>
it becomes data-start_date=<?php echo date("d-m-Y"); ?>

why doesnt it get a Date and stay code?
------------------------------------------------
And to have this set on page load you need to use this code in a "Load JS" action:
2.)a custom load js before form render, onload
jQuery(document).ready(function($){
$("#field_id").data("start_date", '<?php echo date("d-m-Y"); ?>');
});


firebug there is the date of today there instead of php <?php echo date("d-m-Y"); ?>
...seems to work, but no date in the datepickerfield prepopulated...
GreyHead 28 Aug, 2015
Answer
Hi mdma,

The first code example goes in the Extra Params box of the datepicker as it says in the FAQ.

The second example is, I think, the better one to use but you need to replace field_id with the id of your datepicker.

Bob
mdma 28 Aug, 2015
Hello Bob, thanks for clearify the extra params
i tested now the jquery code doesnt set the date into the formfield(nor sets a default variable if i submit there is 1970-...)
but in the jquery the date is ok.

so i dont know the exact purpose of setting the date with jquery or the extra params..(shouldnt it populate the input fields?)

to set a onload date into the fields of the 2 datepicker i did like the other guy in the forum:

<?php
if ( !isset($form->data['Anreise']) || !$form->data['Anreise'] ) {
$form->data['Anreise'] =date("d-m-Y");
}
$d = new DateTime('tomorrow');

if ( !isset($form->data['Abreise']) || !$form->data['Abreise'] ) {
$form->data['Abreise'] =$d->format("d-m-Y");
}
?>
mdma 28 Aug, 2015
Oh sorry i understand now the settings:

its the possibility of selection of the earliest date in the calender datepicker1=nothing before today,datepicker2=nothing before tomorrow selectable
jQuery(document).ready(function($){
$("#datepicker1").data("start_date", '<?php echo date("d-m-Y"); ?>');
$("#datepicker2").data("start_date", ' <?php $d = new DateTime('tomorrow'); echo $d->format("d-m-Y"); ?>')
});

				
mdma 28 Aug, 2015
<?php 
if ( !isset($form->data['datepicker1']) || !$form->data['datepicker1'] ) {$form->data['datepicker1'] =date("d-m-Y");}

$d = new DateTime('tomorrow');
if ( !isset($form->data['datepicker2']) || !$form->data['datepicker2'] ) {$form->data['datepicker2'] =$d->format("d-m-Y");}
?>


then there is preloaded fields before selection
GreyHead 28 Aug, 2015
Hi mdma,

Not tested but that code looks correct. Is it not working?

Bob
mdma 28 Aug, 2015
this is working. but only clearing the basics.
This topic is locked and no more replies can be posted.