Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way I can prevent a kendo datepicker calendar pop-up from closing when clicking on a known container which is outside of the datepicker?

I'm using the kendo datepicker and I have added a textarea at the bottom of the pop-up calendar for users to add comments when changing a date. I have the comments area showing when the datepicker shows but when I click on the textarea to enter comments, the calendar closes. I have try to use e.preventDefault() on the close event of the datepicker but then it never closes.

Is there a way I can prevent a kendo datepicker calendar pop-up from closing when clicking on a known container which is outside of the datepicker?

Code:

Html:

<div class="date-comment-wrapper">
    <textarea id="date-comment" cols="30" rows="5"></textarea>
    <button class="pull-right" id="date-change-submit">Submit Change</button>
</div>

CSS:

.date-comment-wrapper {
    padding: 10px;
    border: 1px solid #c5c5c5;
    width: 225px;
    position: absolute;
    top: 0px;
    left: 0px;
    display:none;
    background-color: white;
    border-radius: 0 0 4px 4px;
}

Javascript to position under datepicker:

var commentDiv = $('.date-comment-wrapper'),
    paddingPlusBorder = 22,
    calendarTopElement = $('.k-animation-container'),
    width = parseFloat(calendarTopElement.css('width')) - paddingPlusBorder,
    height = parseFloat(calendarTopElement.css('height')),
    textArea = commentDiv.children('#date-comment'),
    top = parseFloat(calendarTopElement.css('top')),
    left = parseFloat(calendarTopElement.css('left'));

commentDiv.css({
    width: width,
    left: left,
    top: top + height
});

textArea.css({
    width: width - paddingPlusBorder
});

commentDiv.show();

Kendo Html

<div id='datePicker' style='visibility: hidden; position: absolute;'></div>

Kendo Js

$("#datePicker").kendoDatePicker({
    close: function() {    
        // Close the comment div
        $('.date-comment-wrapper').hide();
    },
    animation: false
});
like image 482
Ovi Avatar asked Nov 11 '22 06:11

Ovi


1 Answers

I am guessing the problem is because your div.date-comment-wrapper containing the textarea and button is outside of the popup (whose code is not shown) and is completely unrelated to the #datePicker.

If you append the div.date-comment-wrapper to your popup window, the window should not close when you click your submit button.

like image 104
Steve Clanton Avatar answered Nov 15 '22 04:11

Steve Clanton