File: /var/www/vhosts/creativefellows.nl/jhtaxatie.creativefellows.nl/public/js/app_jungheinrich.js
$(document).foundation().ready(function(){
// fix image name in upload
$(document).on('change', 'input[type="file"]', function(event){
let files = [];
$(this).next().text("");
for (let i = 0; i < this.files.length; i++) {
files[i] = $("<span class='file'>").text(this.files[i].name);
$(this).next().append( files[i] );
}
});
$(".form__taxation input").on("blur",function(){
let form_fields = $(".form__taxation input[type=text], .form__taxation input[type=file], .form__taxation input[type=email], .form__taxation input[type=number], .form__taxation checkbox, .form__taxation textarea");
let empty_fields = form_fields.filter(function() { return this.value == ""; });
let width = ((form_fields.length - empty_fields.length) / form_fields.length)*100;
$("#taxation-progress .progress-meter").css({ "width" : Math.round(width)+'%' });
$("#taxation-progress .progress-meter-text").text(Math.round(width)+"%");
})
$(".button__toggle").click(function(event){
event.preventDefault();
let fields = $(this).closest("[data-field-group]").find("input, select").filter('[required]');
fields.each(function(){
if($(this).val() == ""){
$(this).addClass("is-invalid-input");
$(this).prev().addClass("is-invalid-label");
$(this).next().addClass("is-visible");
$(this).blur(function(){
if($(this).val() != ""){
$(this).removeClass("is-invalid-input");
$(this).prev().removeClass("is-invalid-label");
$(this).next().removeClass("is-visible");
}
});
}
});
if( $(this).closest("[data-field-group]").find(".form-error:visible").length == 0){
$("#"+$(this).data("hide")).addClass("hide");
$("#"+$(this).data("show")).removeClass("hide");
}
});
$("#step3_confirm").click(function(event){
let data = $(this).closest("form").serializeArray();
let fields = $("#group_confirm").find("[data-copyfield]");
// copy labels to confirm step
fields.each(function(){
let fld = $(this).data("copyfield");
$(this).text( $("[name="+ fld +"]").eq(0).data("label") );
});
// loop data in formo
jQuery.each( data, function( i, field ) {
let copyfield = $("[data-copyfield="+ field.name +"]").next();
if( ['truck_charger','enquiry_type', 'truck_driving', 'truck_lifting'].includes(field.name) )
{
copyfield.text("ja");
}
else if(field.name == "truck_battery")
{
copyfield.text( $("#"+ field.name +" option:eq("+ field.value +")").text() );
}
else if(field.name == "salutation")
{
copyfield.text( $("[name="+ field.name +"]:eq("+ field.value +")").next().text() );
}
else
{
copyfield.text( field.value );
}
});
});
$(".button__back").click(function(event){
$("#"+$(this).data("hide")).addClass("hide");
$("#"+$(this).data("show")).removeClass("hide");
});
$(".page-content .cell").each(function(i, el) {
if ($(el).visible(true)) {
$(el).addClass("already-visible");
}
});
});