Limit selectable date range in parameter calendar selector?

(20 posts) (2 voices)
  1. duane, Member

    I'd using a datetime parameter for a report and the calendar selector is used to select the date. However it includes years in the future which aren't relevant and not enough years in the past. Is there a way to set this range so that the appropriate range is set for the report?

  2. myDBR Team, Key Master

    You can do that with Javascript:

    Assuming your date field is the 3rd parameter (u3), you can use:

    <script> $(document).ready(function() { $("#u3").datepicker( "option", "yearRange", "-50:+0" ); }); </script>
    --
    myDBR Team

  3. myDBR Team, Key Master

    To make life easier, we've added the year range as an option in the latest build.

    --
    myDBR Team

  4. duane, Member

    Thanks! Where do I set the year range? Under 'Other > Year' of 'Report Parameters' when editing the report? Do I put in a range, like you have above in the JS code?

  5. duane, Member

    FYI: just tried -50:+0 under the Edit report > Report Parameters > Other > Year and it worked fine - thanks!

  6. myDBR Team, Key Master

    Yes,
    it's under Report parameters → Other → Year.

    You can use either format "from:to" (1960:2014) or "-years_back:+years_forward" ("-50:+1" becomes "1964 - 2015").

    --
    myDBR Team

  7. duane, Member

    Hi again,

    As this is a related question I thought I'd build on this question from a while back.

    I have a need to set the date-time range as starting from (for example) 3 days from 'today' (DATE(NOW()) in MYSQL) and only extending out maybe 2-3 months - is that possible? If so, how?

  8. myDBR Team, Key Master

    What do you mean by “only extending out maybe 2-3 months”?


    myDBR Team

  9. duane, Member

    > What do you mean by “only extending out maybe 2-3 months”?

    If I only want people to be able to pick a date that is:
    1) Min 5 day after today
    and
    2) Maximum 2 (or three) months from today (or 60 day or 45 day, etc)

    I ask because at times I have people accidentally picking something in the past and/or too far in the future. So preventing this would be very useful!

  10. myDBR Team, Key Master

    There is no built-in functionality to check the dates before the report is run (you can check the dates in the start of the report and inform user about the dates and not run the actual report). You can also check the dates in JS before submitting the parameter form.

    Note that the date picker is not the only way of entering the date. The user can use direct input or use cursor keys to change the dates.

    We can see if date limitation could be added as a feature.
    --
    myDBR Team

  11. duane, Member

    OK - I'll explore other ways. Validation is of course an option and should be done too, but restricting options helps too.

  12. duane, Member

    Just thought, if the mydbr datpicker uses jquery, then the jquery datepicker seems to accept min and max date values (see https://makitweb.com/set-minimum-maximum-date-jquery-ui-datepicker/). Is there a way to pass those to the jquery datepicker or is does that require custom JS?

  13. myDBR Team, Key Master

    There is no option of limiting the dates via a setting. You can use JS for this. To limit an upper limit to March 16, 2022 (in JS Date monthIndex is zero-based), you can use:

    $('#u2').datepicker('option', 'maxDate', new Date(2022, 2, 16) );

    Note that it would just limit the datepicker. The user is still free to choose dates in any other way (directly entering the date, using cursor keys, or from the date range menu).

    Either check the dates when the parameter is submitted or take the easier way and check the dates at the beginning of the report and ask the user to enter another set of dates.

    --
    myDBR Team

  14. duane, Member

    Hi! I'm just back to implementing this...but can't yet get it working. Am I supposed to add the following in the "Help/Javascript" part of the 'Edit' report page:


    <script type='text/javascript'>
    $(document).ready(function(){
    $('#u2').datepicker('option', maxDate, new Date(2022, 2, 16));
    });
    </script>

    The following seems to work - is that how it is intended to be implemented?


    <script type='text/javascript'>
    $(document).ready(function(){
    $('#u2').datepicker('option', {
    'maxDate': '+60d',
    'minDate': '+2d'
    });
    });
    </script>

    Am I implementing it in the wrong place/in the wrong way?

  15. myDBR Team, Key Master

    Note that it is 'maxDate', not maxDate.

    --
    myDBR Team

  16. duane, Member

    Hi again! I'm trying to add the datepicker with mi and max date range to an editable field (vs the parameters example above). I've tried a few ways using the method above AND also tried added editable command:

    'type=datepicker', "options={'minDate': '2022-04-03', 'maxDate': '2022-04-07'}"
    and also
    'type=datepicker', "options={'minDate': new Date(2022, 4, 3), 'maxDate': new Date(2022, 4, 7)}"

    What do I need to do to get it to work (=limit selectable date range to those dates and focus the calendar on those dates)

  17. myDBR Team, Key Master

    For now there is no way of limiting the dates in the editable datepicker. We'll add an option to do that.

    --
    myDBR Team

  18. duane, Member

    Ah - OK. I thought it was something I was doing wrong!

  19. myDBR Team, Key Master

    Duane,
    one can now pass options to the datetime and datepicker:

    "options={datetimepicker:{ 'minDate': new Date(2020, 1, 13), 'maxDate': new Date(2020, 1, 15) }}";

    or

    "options={datepicker:{ 'minDate': '+2d', 'maxDate': '+60d' }}";

    --
    myDBR Team

  20. duane, Member

    Fab!! I'll try this out :-)


Reply

You must log in to post.