So I'm attempting to handle two select lists, such that the sum of their computed values is equal to some max size. i.e., if the maximum number of people is 20, and 5 children are selected - a maximum of 15 adults can be added, and so on.
My last attempt:
template:
<div class="form-row">
<div class="col">
<div class="form-group">
<label for="adultNumber">How many adults are in your party?</label>
<select class="form-control form-control-sm" v-model.lazy="adultNumber" v-on:change="updateChildPartySizes" id="adultNumberVal">
<option v-for="n in maxAdultPartyArray">[[ n ]]</option>
</select>
Answer : [[ adultNumber ]]
</div>
</div>
<div class="col">
<div class="form-group">
<label for="childNumber">How many children are in your party?</label>
<select class="form-control form-control-sm" v-model.lazy="childNumber" v-on:change="updateAdultPartySizes" id="childNumberVal">
<option v-for="n in maxChildPartyArray">[[ n ]]</option>
</select>
Answer : [[ childNumber ]]
</div>
</div>
</div>
Vue instance:
<script>
let app = new Vue({
el: '#app',
data: {
bookingDetails: true,
yourDetails: false,
sessionName: null,
specialRequests: '',
adultNumber: 0,
childNumber: 0,
maxAdultPartySize: 20,
maxChildPartySize: 20,
maxAdultPartyArray: Array.apply(null, {length: 20 + 1}).map(Number.call, Number),
maxChildPartyArray: Array.apply(null, {length: 20 + 1}).map(Number.call, Number),
sessionSize: {{ sessionSize }},
csrfToken : '{{ csrf_token }}',
},
delimiters: ['[[', ']]'],
methods: {
updateChildPartySizes: function (adultNumber) {
this.maxChildPartySize = this.maxChildPartyArray.length - adultNumber;
this.maxChildPartyArray = Array.apply(null, {length: this.maxChildPartySize}).map(Number.call, Number);
},
updateAdultPartySizes: function (childNumber) {
this.maxAdultPartySize = this.maxAdultPartyArray.length - childNumber;
this.maxAdultPartyArray = Array.apply(null, {length: this.maxAdultPartySize}).map(Number.call, Number);
},
}
});
</script>
I've tried a number of things, but not a lot seems to be work. As far as I can see, the Maths and array manipulation is correct ... just not the final desired output...
Help!