Mark Leusink of http://bootstrap4xpages.com has taken Stefan's Datapicker and created an xpages custom control. This control is available here and the code for the custom control is here. If you use this control, you will need to recreate the custom parameters by using this xsp-config file. If you are not using the datepicker in a modal window, then this should work great for you.
Unfortunately for me, I tried for most of a day to get this working in my project but was unsuccessful. The issue that I had was that the date window would not display correctly no matter what I tried.
Full calendar would not display |
I could sort of get the Bootstap datepicker to work but had the following issues.
- Clicking on the data icon would not work, but clicking in the field did work
- The datepicker wouldn't work unless you clicked in the field, clicked out, and then back in
- If you enter a value, then go back in again, the UI would mess up as shown in the screen print
- The datepicker wouldn't close after selecting a value, you had to click outside the calendar to close it
Calendar messed up when re-editing date field |
Here is how I went about fixing this mess.
- I could never get the calendar icon button to click for entering the value. I decided that I would just accept that you click in the field and get the calendar. I think this works fine, even though I would have rather used a button. The default is to highlight today's date which I like.
The finished product - To fix the 2nd and 3rd bullet point above I wrote the code as shown in the screen print. This is because I discovered that $('.datepicker').datepicker('show'); caused it to open correctly the first time, but caused the UI to progressively mess up (see second screenprint) upon editing an existing value. When I used $('.datepicker').datepicker(); then the UI acted normally, and since there was already a value in the field, it worked right away. (I did not want a default value.) This client side javascript code is in the onClick event of the <xp:inputText> tag.
This was the fix to get it to work
3. To get the calendar to close when selecting a value, I added a <xp:scriptBlock> containing: $('.datepicker').datepicker()
.on('changeDate', function(ev){
$('.datepicker').datepicker('hide');
});
The on('changeDate') method is part of the api. There is a similar example on the Bootstrap Datepicker page.
The on('changeDate') method is part of the api. There is a similar example on the Bootstrap Datepicker page.
4. Lastly, you will surely want to turn autocomplete="off". For whatever reason, I was also unable to size the input field using the bootstrap value="input-small" . Because of this, I set the width to using "em", which is a variable sizing measurement. You wouldn't want to use pixels in this case.
Note: I didn't mention earlier, but you have to install the datepicker CSS and Javascript in your database first. In you input field, you MUST set the style to "datepicker".
Update: To use more than one datepicker in a single modal window, wrap each in a <div> with a different id. In the onClick event, reference the id in the jQuery selector.
Update: To use more than one datepicker in a single modal window, wrap each in a <div> with a different id. In the onClick event, reference the id in the jQuery selector.
Conclusion: This whole exercise was a big pain, but necessary. If you are not using a Datepicker in a modal dialog then you are better off using Mark Leusink's custom control or just copy code from Stefan Petre's sight. If you are using a modal dialog to display the calendar date then this will help you. If you have any alternatives or questions, leave a comment.
I wrote a Bootstrap DatePicker and TimePicker just recently using Dojo and I had no problem with having to work with a modal dialog or not.
ReplyDeleteThanks Richard. I didn't spend much time getting the dojo control to work. In hindsight, I think it was a z-index issue, as in it needed to be brought to the front. Love your blog, btw.
ReplyDeleteAnother approach, which you can use if you have control over your users' browsers, is to simply use type="date" for your input control and let the browser take care of the rendering. This approach works in Chrome and Safari, but not Firefox and Internet Explorer. As the support for HTML 5 increases, this will probably be the best way to solve this and similar problems.
ReplyDeleteThanks Saša, I am playing with the 'type' attribute now to make the right keyboard show on mobile. HTML5 is awesome, but I need this to still work on IE8 :( Thanks for the suggestion!
ReplyDeleteThanks for posting your findings.
ReplyDeleteIf you set the autoclose option to true (by default is false) the calendar will close when selecting a value.
$('.datepicker').datepicker({format: "dd/mm/yyyy", autoclose: true });
iam using datepicker in popup but is is now showing in popup instead behind popup its coming help me
ReplyDelete//DATE PICKER
ReplyDelete$('.datepicker').datepicker().on('changeDate', function(ev) {
//
}).on('hide', function(event) {
event.preventDefault();
event.stopPropagation();
});
thanks for article, now problem get solved
ReplyDeleteThanks for sharing the information. I am searching for this for past months.
ReplyDeletecomplete code?
ReplyDeletegood post.... thanks for sharing the information about the datepickers in bootstrap..
ReplyDeletekeep sharing.....
Website Designing Company in Delhi | Website Designing Company in Rohini | Website Designing Company in India | Website Designing Company in Surat | Website Designing Company in ahmedabad | Website Designing Company in jamnagar
Nice article with great idea. Thank you for article.
ReplyDeleteWeb Design India
You are so interesting! I don't believe I've truly read through anything like that before. So wonderful to discover another person with a few unique thoughts on this issue. Seriously.
ReplyDeleteMobile app development
Android app development
Website development
Php web development
Mostly I use to wait for informative article on daily bases to get something new, but today i found your blog very interesting and unique, providing the information helpful to others. Keep it up and waiting for your new updates thanks. We offer multiple services in digital marketing, some of our services are:
ReplyDeleteDigital marketing Company in Delhi
SMM Services
PPC Services in Delhi
Website Design & Development Packages
SEO Services Packages
Local SEO services
E-mail marketing services
YouTube plans
Digital Marketing Service in Delhi
wonderful blog!!
ReplyDeleteThank you so much for sharing this informative blog
web design kolkata
https://www.gowebs.in/web-design-kolkata
amazing article!!
ReplyDeleteThank you
logo design company in kolkata
https://www.gowebs.in/logo-design
As more and more businesses are realizing the importance of having their own online stores, competition among companies providing Ecommerce development services has also increased at a blistering pace. Now it is not sufficient to be an Ecommerce developer as clients demand expertise in latest Ecommerce development platforms like Magento, Shopify, Big Commerce, and Woocommerce.
ReplyDelete