1

I have the jQuery datepicker working, but I need to be able to select more than just dates. I need to be able to select between some strings as well "Yesterday" and "Today" to be precise. So, the underlying input can contain any date as well as the strings "Yesterday" or "Today".

Is there some way I can do this by tweaking the existing jQuery UI datepicker?

1 Answer 1

1

Ultimately, I resorted to just capturing when they click, and if they select Today or Yesterday, putting the word in rather than the actual date.

$('.DatePicker').datepicker({
    showOn: 'button',
    buttonImage: 'images/cal/cal.jpg',
    buttonImageOnly: true,
    changeMonth: true,
    changeYear: true,
    onSelect: function(dateText, inst) {
        var $this = $(this);
        var selected = new Date($this.val());
        var today = new Date();         
        var yesterday = new Date();             
        yesterday.setDate(today.getDate() - 1);

        if (today.toDateString() == selected.toDateString()) {// TODAY
            $this.val('Today');
        } else if (yesterday.toDateString() == selected.toDateString()) {// YESTERDAY
            $this.val('Yesterday');
        }
    }
});

I would have preferred to add a couple buttons to the bottom of the control, but... this will do.

Sign up to request clarification or add additional context in comments.

Comments

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.