{% if setTagDocReady is not defined or setTagDocReady==true %}
<script>
$(document).ready(function () {
{% endif %}
//remove child
$(".childcontainer").on("click", ".removechild", function () {
//console.log("Remove")
var currentGuestCount = parseInt( $(this).parent().parent().parent().parent().children().children().children().children(".update__child").text() );
var updatedCount = parseInt(currentGuestCount - 1);
$(this).parent().parent().parent().parent().children().children().children().children(".update__child").text(updatedCount);
$(this).closest(".search__rooms").remove();
if ( updatedCount === 0 ) {
$('.search__child--update').addClass('d-none');
localStorage.setItem('showChild', null);
localStorage.removeItem('showChild');
} else if (updatedCount <= 1 ) {
$("#occupancy_group_btn .search__child--update .plural").text('Child');
localStorage.removeItem('plural');
localStorage.setItem('single', 'true');
}
});
//add child
$(".search__child").on("click", function () {
$('.search__child--update').removeClass('d-none');
var currentGuestCount = parseInt( $(this).parent().parent().children('.occupany').children().children().children(".update__child").text() );
var updatedCount = parseInt(currentGuestCount + 1);
$('.update__child').each(function(){
$(this).text(updatedCount);
});
{% set formNameChild='childrenAges[]' %}
{% if setFormName is defined and setFormName%}
{% set formNameChild=setFormName~'[childrenAges][]' %}
{% endif %}
$('.childcontainer').append('<div class="search__rooms">' +
' <span class="search__rooms--label">Child age</span>' +
'<select name="{{ formNameChild }}" class="nav-form-control form-control form-primary child-age" required >' +
'<option value="1">1</option>'+
'<option value="2">2</option>'+
'<option value="3">3</option>'+
'<option value="4">4</option>'+
'<option value="5">5</option>'+
'<option value="6">6</option>'+
'<option value="7">7</option>'+
'<option value="8">8</option>'+
'<option value="9">9</option>'+
'<option value="10">10</option>'+
'<option value="11">11</option>'+
'<option value="12">12</option>'+
'<option value="13">13</option>'+
'<option value="14">14</option>'+
'<option value="15">15</option>'+
'<option value="16">16</option>'+
'<option value="17">17</option>'+
'</select>'+
' <a href="#!" class="removechild search__rooms--minus">' +
' <i class="fas fa-minus-circle"></i>' +
' </a>' +
'</div>');
$('.child-age').focus();
if ( $(this).siblings('.childcontainer').children().length >= 2 ) {
$(this).parent().parent().children('.occupany').children().children().children('.plural').text('Children');
localStorage.setItem('plural', 'true');
localStorage.removeItem('single');
} else {
$(this).parent().parent().children('.occupany').children().children().children('.plural').text('Child');
localStorage.removeItem('plural');
localStorage.setItem('single', 'true');
}
localStorage.setItem('showChild', 'true');
});
$(".search__rooms--plus").on("click", function() {
var plus = $(this);
var oldValue = plus.parent().find("input").val();
var inputSource = plus.parent().find("input").data('title');
if (plus.text() == "+") {
if (oldValue < 6) {
var newVal = parseFloat(oldValue) + 1;
} else {
newVal = 6;
}
}
plus.parent().find("input").val(newVal);
$('#' +inputSource ).text(newVal);
});
$(".search__rooms--minus").on("click", function() {
var minus = $(this);
var oldValue = minus.parent().find("input").val();
var inputSource = minus.parent().find("input").data('title');
if (minus.text() == "-") {
if (oldValue > 1) {
var newVal = parseFloat(oldValue) - 1;
} else {
newVal = 1;
}
}
minus.parent().find("input").val(newVal);
$('#' +inputSource ).text(newVal);
});
{% if setTagDocReady is not defined or setTagDocReady==true %}
});
</script>
{% endif %}