0

I am using pickadate.js as a date-picker with the following initialization:

$start_cal_input = $("#start-date-picker").pickadate({
        min: true,
        max: 30,
        editable: true,
        clear: false,
        formatSubmit: 'yyyy/mm/dd',
        hiddenName: true,
        onSet: function(e) {

        },
        onClose: function() {
            return setTimeout(function() {
                return $("#start-date-picker").blur();
            }, 200);
        },
    onStart: function() {
    }
});

and HTML:

<input id="start-date-picker" name="start-date-picker" class="form-control" type="text" value="Start date">

The HTML is posted back to the server in a form, which is used to filter a search criteria. If the user does not actually invoke and select a date with the datepicker, a value of today's today in the 'yyyy/mm/dd' format is being sent to the form, rather than the default value of "Start date". If it is not actually invoked, I don't want to filter my search results by date, but I have no way of distinguishing between the user selecting today's date and the user leaving the date empty and having today's date automatically returned.

How can I determine on form post whether or not the date picker was invoked?

Jim
  • 4,509
  • 16
  • 50
  • 80

1 Answers1

1

Why do you need to send the 'yyyy/mm/dd' format date when user has not selected any date?

you can just use a simple if else statement to know whether the date is selected or not. An example would look like below

if(date is empty or is a default value) {
    do some thing
}else {
    do some other thing
}

this way hou can know if the date was selected by the user. And most importantly server will not be able to check whether the javascript was executed or not until and unless you set a flag or a value in your form. I would like to say that there are ways to do this you just need to know about it :)

EDIT

Have this extra input type as hidden.

<input type="hidden" name="isdateselected" id="myDateFlag" value="false" />

onSet: function(context) {
    document.getElementById("myDateFlag").value="true";
}

Now you could use the isdateselected parameter to check whether the date was selected or not. If it is selected its true else its false

Vinay
  • 6,891
  • 4
  • 32
  • 50
  • I don't need to send it in 'yyyy/mm/dd' value when the user has not selected any date, but that is what is being returned. I would love to have something radically different that would be easy to detect server/side, but pickadate.js is passing it that way automagically.. – Jim Aug 04 '14 at 16:43
  • [Here](https://github.com/amsul/pickadate.js/issues/94) you can find an answer about how to make a default value. – Vinay Aug 04 '14 at 16:55
  • I'd looked at that, but if you don't allow the user to select dates from the past you can't set a default value in the past (it auto-sets to today's date), which puts us back at square 1, unfortunately. Thanks for the digging though – Jim Aug 04 '14 at 16:59
  • Thanks. I was wondering if there was a way around this but it is probably the easiest solution at this point. Appreciated :) – Jim Aug 04 '14 at 17:21