Forums

Datepicker custom? validation

mdma 27 Aug, 2015
Hello again:
I have searched alot but maybe its an easy answer for specialists?

1)I need the datepicker like i think thats in the FAQ and kind of also here:

1a.)datepicker1 is set minimum today ....
data-start_date=<?php echo date("d-m-Y"); ?>

1b.)datepicker2 is set minimum datepicker +1day .....
data-start_date=<?php $d = new DateTime('tomorrow'); echo $d->format("d-m-Y"); ?>


2.)datepicker1 if user selects date some day in the future
datepicker2 should switch date automatically future +1day (How to do?how to call this in google)
2a)
$("#datepicker1").on("select_date.gdatetimepicker", function(){
//event code here  change datepicker2 +1day from datepicker1??
});

2b)
var startDate = new Date($('#datepicker1').val());
var endDate = new Date($('#datepicker2').val());

if (startDate < endDate){
// Do something
everything ok
}

3.)how to also validate immideatly(before submit):
datepicker1 <datepicker2 and datepicker1 minimum "todays date"
GreyHead 28 Aug, 2015
Hi mdma,

1) I think you have answered

2) and 3) both need custom JavaScript. For 2) you'd need to reset the start-date for the second picker (and I guess remove any set date if it was earlier). For 3) you'd add a custom validation function.

Bob
mdma 28 Aug, 2015
On selection made

data-on_date_selected=date_change

That code would call a JS function named "date_change" after the date selection has been made, you can use this to set the start date of another field.

ok that goes into extra params of datpicker1 ? i need a code like the following (taken from jqueryUIdatepicker i want to translate to gdatetimepicker

    $(document).ready(function () {

        $("#dt1").datepicker({
            
            minDate: 0,
            onSelect: function (date) {
                var dt2 = $('#dt2');
                var startDate = $(this).datepicker('getDate');
                var minDate = $(this).datepicker('getDate');
                dt2.datepicker('setDate', minDate);
                startDate.setDate(startDate.getDate() + 1);
                //sets dt2 maxDate to the last day of 30 days window
                dt2.datepicker('option', 'minDate', startDate);
                dt2.datepicker('option', 'minDate', minDate);
                $(this).datepicker('option', 'minDate', minDate);
            }
        });
        $('#dt2').datepicker({
            
        });
    });

have you an idea to get this working?
GreyHead 28 Aug, 2015
1 Likes
Hi mdma,

Not without sitting down and working through it. If you have code for the jQueryUI date-picker you could use that instead of the CF one?

Bob
mdma 01 Sep, 2015
Hello Bob,
I will follow your advice and will go with jqueryui datepicker, because its more expandable, documented,
why isnt chronoforms standradized with jqueryUI datepicker already?
will there incopatibility issiues arise with some actions/email template perhaps?
GreyHead 01 Sep, 2015
Answer
Hi mdma,

I don't know why Max chose to write his own datepicker, you'd need to ask him.

There shouldn't be any incompatibility - all that is submitted is a date string.

Bob
mdma 01 Sep, 2015
thank you!
This topic is locked and no more replies can be posted.