0

I am wanting to pull data from a database (i'm using Laravel as the framework) that has a selection of dates to then show the user on the frontend calendar these dates are unavailable and block them out so they can't select them.

My db structure is:

enter image description here

I have the standard code from jQueryUI website:

<link rel="stylesheet" href="/css/redmond/jquery-ui-1.10.4.custom.css">
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
    $(function() {
        $( "#from" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 2,
            onClose: function( selectedDate ) {
                $( "#to" ).datepicker( "option", "minDate", selectedDate );
            }
        });
        $( "#to" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 2,
            onClose: function( selectedDate ) {
                $( "#from" ).datepicker( "option", "maxDate", selectedDate );
            }
        });
    });
</script>

So how would I get my data into the calendar to display only available dates. I'm trying to make a simple reservation calendar.

Thanks in advanced.

1 Answer 1

1
  • Query the database and get an array of dates:

var dates = ["2013-03-14","2013-03-15","2013-03-16"]

  • Disable the dates

Use beforeShowDay, something like this:

beforeShowDay: function(date) {
    var d = $.datepicker.formatDate('yy-mm-dd', date);
    return [ dates.indexOf(d) == -1 ]
}
Sign up to request clarification or add additional context in comments.

3 Comments

There are several ways to approach this. You need to share your code of what you've done so far so that others would be able to help you. People here aren't going to write you the code from scratch.
OK its more the stuff you put earlier JS is not my strong point, I can sort the PHP, thanx dude.
Thanks appreciate your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.