Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change position of Datepicker inside Modelpopup textbox

I am working on a ASP.Net webform which includes AJAX Modelpoup Extender and jquery nepali-datepicker. I have to integrate nepali-datepicker to a textbox that is inside my second modelpopup i.e. with blue background shown in image below. Problem I am facing is that I am not able to position datepicker at bottom of textbox

Based on answers on the post(How to change the pop-up position of the jQuery DatePicker control) I was able to bring datepicker in front of 2nd model popup. Is there a way that I can use to actually position datepicker to the textbox.

Here is my script and styles:

<script type="text/javascript">        
    function pageLoad() {
        $('.nepali-calendar').nepaliDatePicker();
    }

    $(document).ready(function () {
        $('.nepali-calendar').nepaliDatePicker();

    });
</script>    

<style type="text/css">
    div#ndp-nepali-box
    {
        position:absolute;
        z-index: 999999;
    }
</style>

Following image shows how it is is positioned right now.enter image description here

If I use position as relative.

<style type="text/css">
    div#ndp-nepali-box
    {
        position: relative;
        z-index: 999999;
    }
</style>

It looks like enter image description here

Is there a way that I can use to actually position datepicker to bottom of the textbox.

like image 430
TFrost Avatar asked Jul 01 '15 15:07

TFrost


People also ask

How to set the position of the popup in datepicker?

In the same way we can set the position of the popup where ever needed just by setting “marginTop” and “marginLeft” attributes. Here beforeShow () is the method exposed by datepicker widget.

How to change the position of the jQuery UI datepicker?

To change the position of the jQuery UI Datepicker just modify .ui-datepicker in the css file. The size of the Datepicker can also be changed in this way, just adjust the font size. @gfrizzle - yep, that answer of mine was just so wrong.

How do I add a datepicker to a modal?

Open the modal and click on the input field. The datepicker will pop up. Now scroll the page. You will see that the datepicker doesn't scroll with the page – it just stays at the exact position where it was placed at the beginning. Sorry, something went wrong.

How to make the popup appear at the side of text?

But the default popup position is just below the text box so we had to work around to make it appear at the side.. The following code block in document.ready method demonstrates the hack: In the same way we can set the position of the popup where ever needed just by setting “marginTop” and “marginLeft” attributes.


1 Answers

As you are using jquery UI Datepicker it should have beforeShow property and change css inside this property like below.

Check this fiddle

$('input.date').datepicker({
beforeShow: function(input, inst) {
 var cal = inst.dpDiv;
 var top  = $(this).offset().top + $(this).outerHeight();
 var left = $(this).offset().left;
 setTimeout(function() {
    cal.css({
        'top' : top,
        'left': left
    });
 }, 10);
}
});

Reference

like image 63
Light Avatar answered Nov 15 '22 05:11

Light