I’m a bit confused right now.
For a customer project, I need to use Vue.js version 2.
In a component, I have 2 iterations across some field definition JSONs that use <template>
with v-for
.
Whichever iteration of these I put first, will get ignored – the content never shows up. If I change their order, it will be the respective other one.
<EssentialSmartForm v-if="customForm"
id="customForm"
v-bind:form-config="customForm"
v-bind:hide-submit-button="true"
@form-change="saveForm($event)"
@form-submittable-change="setFormIsValid($event)">
<!-- Whichever of the following iterations comes first, never gets rendered! If I change the order, it's the respective other one -->
<!-- Iterates over uploadFieldConfigs; fieldConfig will be the child object, key will be the key under which it is stored as part of uploadFieldConfigs -->
<!-- '#' is a shorthand for v-slot: (referencing the slot name dynamically is easier with the shorthand) https://vuejs.org/guide/components/slots.html#dynamic-slot-names -->
<!-- '=data' passes in the field data, and we pass name and field in EssentialSmartForm, cf. https://vuejs.org/api/built-in-directives.html#v-slot -->
<template v-for="(fieldConfig, key) in uploadFieldConfigs" #[fieldConfig.slotName]="data">
<p :key="key + '_upload_debug1'" v-dompurify-html="'Key: |' + key + '| Data: |' + JSON.stringify(data) + '|'"></p>
</template>
<template v-for="(fieldConfig, key) in searchFieldConfigs" #[fieldConfig.slotName]="slotProperties">
<p :key="key + '_upload_debug2'" v-dompurify-html="'Key: |' + key + '| Data: |' + JSON.stringify(slotProperties) + '|'"></p>
</template>
</EssentialSmartForm>
(I removed the real content and just put some debug output.)
The EssentialSmartForm around provides all the data / slotProperties that are needed.
For the given form’s fields, it will create the needed slots, that part works.
<template>
<div class="c_smart-form-wrapper">
<div v-if="!this.hideTableOfContents"
class="c_smart-form-content-container generals-animate"
v-bind:class="{'m--collapsed': !tableOfContentExpanded}">
<div class="c_smart-form-content-header">
<span>{{$tc('smartForm.tableOfContents')}}</span>
</div>
<div v-bind:id="`c_smart-form-body_${formConfig.id}`"
class="c_smart-form-body">
<div class="c_smart-form-fields">
<transition-group name="show" tag="div">
<template v-for="(field, fieldIndex) in getSelectedSection.fields">
<div v-if="isFieldVisible(field)"
v-bind:key="`${field.id}_${pageSelectionIndex}`"
class="c_smart-form-field"
v-bind:class="{
'm--missing': isRequiredButFalsy(field) && showMissingValues,
'm--no-margin': field.originalId
}">
<!-- [...] -->
<div v-else-if="field.type === 'Slot'">
<slot v-bind:name="`field(${field.id})`"
v-bind:field="field">
</slot>
</div>
</div>
</template>
</transition-group>
</div>
</div>
</div>
</div>
</template>
I can easily work around the issue by removing one of the v-for iterations and spelling out what I have in the iterated-over JSON, but I’m curious whether this is a bug in Vue.js, or if there is some restriction that the team and I overlooked in the docs.
Do tell if this is too little information to go on, or if you need a minimal working example!
(I’m still thinking this may be a general thing, and it may not be worth the effort to exract a working example from the code base – but I’ll gladly do it if required.)