I have a page which contains a form and few fields. My issues are as follow:
Here is my jQuery:
JQUERY:
$( document ).ready(function() {
// Set Datepicker
$(".datepicker").datepicker();
$("input").focus(function () {
$('html, body').animate({ scrollTop: $(this).offset().top - 25 }, 10);
});
});
Link to a fiddle: https://jsfiddle.net/MauriceT/0qfycgm1/10/
Here is what I want to avoid:
Datepicker displays above the input field
Any suggestions would be greatly appreciated. Thanks!
you can achieve your goal by setting the css of the date picker pop.
Use the below code to set the CSS, the use of setTimeout is to avoid the overriding of the CSS.
Here i am finding out the top and left of the date time picker text box and using these value to set the position of the date time picker popup
On the information about beforeShow event check here.
https://api.jqueryui.com/datepicker/#option-beforeShow
$(".datepicker").datepicker({
beforeShow: function (input, inst) {
setTimeout(function () {
inst.dpDiv.css({
top: $(".datepicker").offset().top + 35,
left: $(".datepicker").offset().left
});
}, 0);
}
});
Here is the fiddle : https://jsfiddle.net/0qfycgm1/14/
A simple fix is by adjusting the frontend using CSS for the CALENDER Box.
Add the following to your CSS file.
.ui-datepicker{
margin-top: 300px;
}
I tried it in your Fiddle link, was working perfectly fine.
add
ui-datepicker{
margin-top: 0px;
}
I have added this code to your fiddle and have tested it. hope this will help. have updated your fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With