Hi @nelitow!
We added an extra fieldset with a snipcart input (id=“ophaalmoment”) to the billing section. Additonaly we’ve added a link which activates the javascript plugin.
<billing section="bottom">
<fieldset class="snipcart-form__set">
<div class="snipcart-form__field">
<snipcart-label class="snipcart__font--tiny" for="ophaalMoment">
Afhaalmoment in de winkel (Markt 16, Oedelem)
</snipcart-label>
<snipcart-input name="ophaalMoment" id="ophaalmoment"></snipcart-input>
</div>
<a href="javascript:AddDatePicker()" id="kiesdatum" class="button secondary">Kies een datum</a>
</fieldset>
</billing>
Upon clicking the link, the AddDatePicker() function is executed. It adds a datepicker component to the rendered input which we can find by using the first input child .
To be sure, the rendered input value is set an extra time.
<script>
/* OPTIE 3 datepicker met js-datepicker: https://github.com/qodesmith/datepicker#readme*/
function AddDatePicker(){
// zoek de juiste inputbox
let firstInputChildIDValue = $("#ophaalmoment input:first-child").attr('id');
// zet de inputbox als vereist
$('#'+ firstInputChildIDValue).prop('required',true);
// de vroegst mogelijke datum om op te komen halen
var firstpossibledate = new Date();
firstpossibledate.setDate(firstpossibledate.getDate() + 2);
console.log("firstpossibledate "+ firstpossibledate )
try {
const picker = datepicker('#'+ firstInputChildIDValue, {
startDay: 1,
minDate: firstpossibledate,
disabler: date => (date.getDay() === 1), // Disabled every Monday
customDays: ['Zo', 'Ma', 'Di', 'Woe', 'Do', 'Vr', 'Za'],
customMonths: ['Jan', 'Feb', 'Maa', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
onSelect: (instance, gekozendatum) => {
// Do stuff when a date is selected (or unselected) on the calendar.
$('#'+ firstInputChildIDValue).val("afhalen op "+ gekozendatum);
}
});
console.log("kalender toegevoegd aan de input met ID:"+ firstInputChildIDValue );
}
catch (e) {
console.log("kalender toevoegen niet gelukt");
}
finally {
$('#'+ firstInputChildIDValue).focus();
}
};
</script>
I hope this gives you some insight into our problem.
Thanks!