javascript - How to target bootstrap datepicker's its own '.datepicker-dropdown' when there is multiple datepickers in a page.?(without container option) -
in project - app, have multiple datepicker version 2.0. client wants me customise datepicker showing date of calendar top, did tweaks, working on page 1 datepicker it's story when comes multiple datepicekers on 1 page.my code follows.
$(elem).datepicker(options); //customized datepicker plugin 03/07/2017 //author - jithin raj var date = new date(); var today = new date(date.getfullyear(), date.getmonth(), date.getdate()); $(elem).on('show', function() { var cpicval = '', ypicval = ''; if ($('.datepicker-dropdown').find('.new-date-wrap').length <= 0) { $('.datepicker-dropdown').prepend('<div class="new-date-wrap"><div class="custom-year-pic-view"><span></span></div><div class="custom-day-pic-view"><span></span></div></div>'); } if ($(elem).val() == '') { cpicval = (date.parse(today).tostring('ddd, mmm dd')); ypicval = (date.parse(today).tostring('yyyy')); } else { cpicval = (date.parse($(elem).val()).tostring('ddd, mmm dd')); ypicval = (date.parse($(elem).val()).tostring('yyyy')); } $('.custom-day-pic-view').find('span').text(cpicval); $('.custom-year-pic-view').find('span').text(ypicval); }); });
can suggest me fullprofe method, thankyou cheers..
i think on answer,i changed code little bit , added moment.js
and working on app.
$(elem).datepicker(options); //customized datepicker plugin 03/07/2017 //author - jithin raj var date = new date(); var today = new date(date.getfullyear(), date.getmonth(), date.getdate()); $(elem).on('show', function() { var cpicval = '', ypicval = ''; elem = $(this) if ($('.datepicker-dropdown').find('.new-date-wrap').length <= 0) { $('.datepicker-dropdown').prepend('<div class="row-fluid new-date-wrap"><div class="row-fluid custom-year-pic-view"><span></span></div><div class="row-fluid custom-day-pic-view"><span></span></div></div>'); } if ($(elem).val() == '') { cpicval = (moment(today).format('ddd, mmm dd')); ypicval = (moment(today).format('yyyy')); } else { cpicval = (moment($(elem).val()).format('ddd, mmm dd')); ypicval = (moment($(elem).val()).format('yyyy')); } $('.custom-day-pic-view').find('span').text(cpicval); $('.custom-year-pic-view').find('span').text(ypicval); });
its working me if working please upvote it, hope helps you. cheers.
Comments
Post a Comment