diff --git a/js/app/date_poll.js b/js/app/date_poll.js index 43601dadf246dc27b85bedc5a123e7ba8c16db50..db90cbdeac0f1b91fdb1588137c4309b68886261 100644 --- a/js/app/date_poll.js +++ b/js/app/date_poll.js @@ -75,8 +75,8 @@ $(document).ready(function () { function getLastDayNumber(last_day) { if (last_day == null) - last_day = $selected_days.find('fieldset').filter(':last') - return parseInt(/^d([0-9]+)-h[0-9]+$/.exec(last_day.find('.hours').filter(':first').attr('id'))[1]) + last_day = $selected_days.find('fieldset').filter(':last'); + return parseInt(/^d([0-9]+)-h[0-9]+$/.exec($(last_day).find('.hours').filter(':first').attr('id'))[1]) } function newDateFields(dateStr) { @@ -102,6 +102,14 @@ $(document).ready(function () { $removeaday_and_copyhours.removeClass('disabled'); } + function manageRemoveadayAndCopyhoursButtons() { + var nb_days = $selected_days.find('fieldset').length; + $('#day' + (getLastDayNumber() - 1)).focus(); + if (nb_days == 1) { + $removeaday_and_copyhours.addClass('disabled'); + } + } + var useFirstEmptyDateField = function (dateStr) { var used = false; $selected_days.find('fieldset legend input').each(function () { @@ -225,12 +233,7 @@ $(document).ready(function () { $('#remove-a-day').on('click', function () { $selected_days.find('fieldset:last').remove(); - var nb_days = $selected_days.find('fieldset').length; - - $('#day' + (getLastDayNumber() - 1)).focus(); - if (nb_days == 1) { - $removeaday_and_copyhours.addClass('disabled'); - } + manageRemoveadayAndCopyhoursButtons(); submitDaysAvalaible(); }); @@ -240,6 +243,7 @@ $(document).ready(function () { if ($('#days_container').find('fieldset').length > 1) { $(this).parents('fieldset').remove(); } + manageRemoveadayAndCopyhoursButtons(); submitDaysAvalaible(); });