Merge branch 'fix/Date_picker_doesnt_appear' into 'develop'
Fix: date picker that doesn't appear when clicking on calendar icon Move JS code about date picker from `js/app/core.js` to `js/app/framadatepicker.js` See merge request !43
This commit is contained in:
commit
6b2937bf2e
@ -15,7 +15,7 @@
|
|||||||
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
||||||
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
||||||
*/
|
*/
|
||||||
$(document).ready(function() {
|
$(document).ready(function () {
|
||||||
var init_datepicker = function () {
|
var init_datepicker = function () {
|
||||||
$('.input-group.date').datepicker({
|
$('.input-group.date').datepicker({
|
||||||
format: "dd/mm/yyyy",
|
format: "dd/mm/yyyy",
|
||||||
@ -25,16 +25,19 @@ $(document).ready(function() {
|
|||||||
language: lang,
|
language: lang,
|
||||||
todayHighlight: true,
|
todayHighlight: true,
|
||||||
beforeShowDay: function (date) {
|
beforeShowDay: function (date) {
|
||||||
var $selected_days = [];
|
// Retrieve selected dates from text fields
|
||||||
|
var selected_days = [];
|
||||||
$('#selected-days').find('input[id^="day"]').each(function () {
|
$('#selected-days').find('input[id^="day"]').each(function () {
|
||||||
if ($(this).val() != '') {
|
if ($(this).val() != '') {
|
||||||
$selected_days.push($(this).val());
|
selected_days.push($(this).val());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (var i = 0; i < $selected_days.length; i++) {
|
|
||||||
var $selected_date = $selected_days[i].split('/');
|
|
||||||
|
|
||||||
if (date.getFullYear() == $selected_date[2] && (date.getMonth() + 1) == $selected_date[1] && date.getDate() == $selected_date[0]) {
|
// Disable selected dates in DatePicker
|
||||||
|
for (var i = 0; i < selected_days.length; i++) {
|
||||||
|
var selected_date = selected_days[i].split('/');
|
||||||
|
|
||||||
|
if (date.getFullYear() == selected_date[2] && (date.getMonth() + 1) == selected_date[1] && date.getDate() == selected_date[0]) {
|
||||||
return {
|
return {
|
||||||
classes: 'disabled selected'
|
classes: 'disabled selected'
|
||||||
};
|
};
|
||||||
@ -44,16 +47,26 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$(document).on('click', '.input-group.date .input-group-addon', function () {
|
||||||
|
// Re-init datepicker config before displaying
|
||||||
|
init_datepicker();
|
||||||
|
$(this).parent().datepicker('show');
|
||||||
|
|
||||||
|
// Trick to refresh calendar
|
||||||
|
$('.datepicker-days .prev').trigger('click');
|
||||||
|
$('.datepicker-days .next').trigger('click');
|
||||||
|
});
|
||||||
|
|
||||||
// Complete the date fields when use partialy fill it (eg: 15/01 could become 15/01/2016)
|
// Complete the date fields when use partialy fill it (eg: 15/01 could become 15/01/2016)
|
||||||
|
|
||||||
var leftPad = function(text, pad) {
|
var leftPad = function (text, pad) {
|
||||||
return text ? pad.substring(0, pad.length - text.length) + text : text;
|
return text ? pad.substring(0, pad.length - text.length) + text : text;
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).on('change', '.input-group.date input', function () {
|
$(document).on('change', '.input-group.date input', function () {
|
||||||
// Complete field if needed
|
// Complete field if needed
|
||||||
var val = $(this).val();
|
var val = $(this).val();
|
||||||
var capture = /([0-9]+)(?:\/([0-9]+))?/.exec(val);
|
var capture = /^([0-9]+)(?:\/([0-9]+))?$/.exec(val);
|
||||||
|
|
||||||
if (capture) {
|
if (capture) {
|
||||||
var inputDay = leftPad(capture[1], "00"); // 5->05, 15->15
|
var inputDay = leftPad(capture[1], "00"); // 5->05, 15->15
|
||||||
|
22
js/core.js
22
js/core.js
@ -2,28 +2,6 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
window.lang = $('html').attr('lang');
|
window.lang = $('html').attr('lang');
|
||||||
|
|
||||||
var datepickerfocus = false; // a11y : datepicker not display on focus until there is one click on the button
|
|
||||||
|
|
||||||
$(document).on('click','.input-group.date .input-group-addon', function() {
|
|
||||||
datepickerfocus = true;
|
|
||||||
// Re-init datepicker config before displaying
|
|
||||||
$(this).parent().datepicker(init_datepicker());
|
|
||||||
$(this).parent().datepicker('show');
|
|
||||||
|
|
||||||
// Trick to refresh calendar
|
|
||||||
$('.datepicker-days .prev').trigger('click');
|
|
||||||
$('.datepicker-days .next').trigger('click');
|
|
||||||
// .active must be clicable in order to unfill the form
|
|
||||||
$('.datepicker-days .active').removeClass('disabled');
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('focus','.input-group.date input', function() {
|
|
||||||
if(datepickerfocus) {
|
|
||||||
$(this).parent('.input-group.date').datepicker(init_datepicker());
|
|
||||||
$(this).parent('.input-group.date').datepicker('show');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adminstuds.php
|
* adminstuds.php
|
||||||
**/
|
**/
|
||||||
|
Loading…
Reference in New Issue
Block a user