sub_startdate adding to a calendar

Hello All,

So we have implemented the sub_frequency code into the form, but is there a way to implement the sub_startdate and tie it to the element so that our uses can select when they want the payments to start.

Thank you
Comments
  • fc_adamfc_adam FoxyCart Team
    @kdawg1981,

    Thanks for posting - I believe you're wanting to support a calendar widget as part of the form for the customer to select a start date for their subscription, is that right?

    If so - that's definitely possible to do. You would set up your form with the sub_startdate input, and attach a calendar widget to it. HTML5 has a date/time input type, but cross-browser support isn't great, so using a javascript library is probably still your better approach to ensure a consistent experience for your users.

    I've just created a page on our wiki for showing approaches for that using two different libraries - you can see that here: https://wiki.foxycart.com/v/2.0/snippets/date_picker_for_sub_startdate
  • @fc_adam Thank you. This helped a lot. I appreciate it.
  • @fc_adam Here is a question. so we have the sub_start date implemented with a datepicker but when we are testing and select the date as today, it will display this on the checkout ("20181204 does not represent a date in the future") Is there a way for us to implement a way for the customer to choose today's date if they want the subscription to start today?
  • fc_adamfc_adam FoxyCart Team
    @kdawg1981,

    Good question. It should be ok to select todays date - but as you're seeing, the cart is complaining that it's not todays date. Our validations currently require the start date be in the future - but I can definitely see how allowing it to be today makes sense too. We'll ticket that on our side to look into for a future enhancement.

    For now - you could set up your add to cart form to initially hide the "sub_startdate" datepicker option, and instead show a checkbox for the customer to designate that they want the subscription to start at a future date. If they don't check that, then you wouldn't pass any "sub_startdate" parameter with the form, allowing the sub to start immediately. If they did check it though, then you'd show the datepicker, and restrict it to only allow them to select a date starting with tomorrows date.

    Could that work with your set up?
  • @fc_adam I was able to figure this out by writing some javascript to fix this.
  • fc_adamfc_adam FoxyCart Team
    @kdawg1981, awesome, thanks for the update!
  • kdawg1981kdawg1981 Member
    @fc_adam So I think that I ran into a snag when I created the calendar for support in Safari. So when I do select a date from the calendar, I get this error in Safari now and I'm not sure what I did or need to do to fix this. Here is the error: 12/14/2018 must be a valid date in the yyyymmdd format, a valid day of the month in the dd or d format, or the subscription frequency format such as 1m or 30d (one month or thirty days in the future). Here is the code I have for the datepicker to work in safari:
    <script type="text/javascript">
    var datefield=document.createElement("input")
    datefield.setAttribute("type", "date")
    if (datefield.type!="date"){ //if browser doesn't support input type="date", load files for jQuery UI Date Picker
    document.write('<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />\n')
    document.write('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"><\/script>\n')
    document.write('<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"><\/script>\n')
    }
    </script>

    <script>
    if (datefield.type!="date"){ //if browser doesn't support input type="date", initialize date picker widget:
    jQuery(function($){ //on document.ready
    $('#date').datepicker();
    altFormat: "yyyy-mm-dd"

    });
    }
    </script>
Sign In or Register to comment.