This is a migrated thread and some comments may be shown as answers.

[Solved] Triggering onChange() for datepicker

0 Answers 32 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Shea
Top achievements
Rank 1
Shea asked on 02 Feb 2012, 12:19 AM
Hello,

In my date.cshtml editor template, I have added a 'today' anchor to automatically put todays day the datepicker field.  This saves a lot of time in our application.

I accomplish it like this:
@{
    var datepicker = Html.Telerik().DatePicker()
        .Format("dd MMM yyyy")
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .HtmlAttributes(new { id = ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty) + "_wrapper" })
        .Value(Model);
}
 
@datepicker | <a href="#" onclick="DatePickerTodayClicked(event,  @ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)');">today</a>


My DatePickerTodayClicked looks like this:
function DatePickerTodayClicked(e, datePickerId) {
    var id = '#' + datePickerId.replace('.', '_');
 
    var input = $(id);
    if (input == null) {
        alert('"ERROR: input ' + id + ' not found.');
        return;
    }
 
    var picker = input.data('tDatePicker');
    if (picker == null) {
        alert('ERROR: date picker ' + id + ' not found.');
        return;
    }
    picker.value(new Date());
    e.preventDefault();
}

This works great.... but when I subscribe to the OnChange client event of a datepicker in my applications, they don't get executed when the today link is clicked.

I tried calling picker.onChange(); manually, but that just results in a crash. Is there something I can do to get this working?
Tags
Date/Time Pickers
Asked by
Shea
Top achievements
Rank 1
Share this question
or