javascript - Clearing the Kendo Datepicker input field from the footer - Stack Overflow

I'm trying to put a button in my Kendo Datepicker footer that can be used to clear the input field

I'm trying to put a button in my Kendo Datepicker footer that can be used to clear the input field, but the Datepicker treats any text or button in the footer as a shortcut for the current date. Does anyone know how to override this behaviour?

Thanks

My current code:

<input id="datepicker" />

<script id="footer-template" type="text/x-kendo-template">
    <button id="myButton" onclick="myFunction" >Click Me!</button>
</script>
<script>
function myFunction() {
    document.getElementById("datepicker").value = '';
}

$("#datepicker").kendoDatePicker({
    footer: kendo.template($("#footer-template").html())
});
</script>

I'm trying to put a button in my Kendo Datepicker footer that can be used to clear the input field, but the Datepicker treats any text or button in the footer as a shortcut for the current date. Does anyone know how to override this behaviour?

Thanks

My current code:

<input id="datepicker" />

<script id="footer-template" type="text/x-kendo-template">
    <button id="myButton" onclick="myFunction" >Click Me!</button>
</script>
<script>
function myFunction() {
    document.getElementById("datepicker").value = '';
}

$("#datepicker").kendoDatePicker({
    footer: kendo.template($("#footer-template").html())
});
</script>
Share Improve this question asked May 13, 2015 at 0:00 JamsesJamses 511 gold badge1 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

I was able to do this using the "remove link" example here:

http://www.telerik./forums/datepicker-custom-footer-without-link

My new code:

<input id="datepicker" />

<script id="footer-template" type="text/x-kendo-template">
    #=text#
</script>
<script>
$("#datepicker").kendoDatePicker().getKendoDatePicker().one("open", function(e) {
  var t = kendo.template($("#footer-template").html());
  var dp = this;
  setTimeout(function(){
    dp.dateView.popup.wrapper.find(".k-footer").append(t({text: "<button id=\"myButton\" onclick=\"myFunction()\" >Clear</button>"}));
  });
});

function myFunction() {
    $("#datepicker").data("kendoDatePicker").value(null);
}
</script>

Unable to test it at the moment, but you probably need something like this, using value() to set the new date:

<script>
    $("#myButton").on("click", function (e) {
        e.preventDefault();
        $("#datepicker").data("kendoDatePicker").value(null);
    });

    $("#datepicker").kendoDatePicker({
        footer: kendo.template($("#footer-template").html())
    });
</script>

<input id="datepicker" />

<script id="footer-template" type="text/x-kendo-template">
    <button id="myButton">Click Me!</button>
</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744962556a4603477.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信