How to limit the options of a date field?

How to limit the options of a date field?

nsaknsak Posts: 36Questions: 6Answers: 0

hi,

when creating a new entry to the table I am building, the user needs to fill two date fields, one for the start-date, and one for the end-date. So, I need to make sure that the end-date is after the start-date. In order to do that I used the following code in order to limit the options the user gets once having selected one of the two dates, but it didn't work:

                   $('date', editor.field('manage.from_date').node()).datepicker({
            onSelect: function(selected) {
                $('date', editor.field('manage.to_date').node()).datepicker("option","minDate", selected);
            }
        });

         $('date', editor.field('manage.to_date').node()).datepicker({
            onSelect: function(selected) {
                $('date', editor.field('manage.from_date').node()).datepicker("option","maxDate", selected);
            }
        });

(Manage is the id of my table and from_date, to_date the values of the two date input fields).

Any help would be really useful. Thanks!

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Hi,

    $('date', editor.field('manage.from_date').node())

    That is trying to select a date HTML element. Try:

    $('input', editor.field('manage.from_date').node())
    

    Which will select the input element and then act on that.

    Allan

  • nsaknsak Posts: 36Questions: 6Answers: 0

    right, it works now.
    thanks a lot Allan!

  • nsaknsak Posts: 36Questions: 6Answers: 0

    Allan, are you sure the above code is fine? Beacuse when I try to run it doesn't work. Specifically, I have tried it on 2 different computers and on the first one sometimes the validation works but the date widget doesn't appear correctly and sometimes the opposite, the widget works fine but not the validation. And on the second computer the validation doesn't work at all, though the widget appears correctly.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Are you able to link to the page so I can debug it please?

    Allan

  • nsaknsak Posts: 36Questions: 6Answers: 0

    No, unfortunately not yet.

    Is it possible that datepicker is not used?

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Is it possible that datepicker is not used?

    Yes quite possible. If jQuery UI date picker has not been loaded on the page, then the HTML5 <input type="date"> input will be used instead. Currently only Chrome actually implements that on the desktop, but others will hopefully follow suit soon.

    Allan

This discussion has been closed.