Is it possible to link the number of elements in a ListElement to another element? #251
-
For example, could you have a |
Beta Was this translation helpful? Give feedback.
Answered by
adamberecz
May 25, 2024
Replies: 1 comment 1 reply
-
Here's one way of achieving it: <template>
<Vueform ref="form$" v-bind="form" />
</template>
<script setup>
import { ref } from 'vue'
const form = ref({
schema: {
number: {
type: 'text',
onChange(newNumber, oldNumber, el$) {
const list$ = el$.form$.el$('list')
const number = parseInt(newNumber) || 0
if (list$.value.length < number) {
for (let i = list$.value.length; i < number; i++) {
list$.add()
}
}
else if (list$.value.length > number) {
for (let i = list$.value.length; i > number; i--) {
list$.remove(i)
}
}
}
},
list: {
type: 'list',
controls: {
add: false,
remove: false,
},
element: {
type: 'text'
}
}
}
})
</script> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
pwicks86
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's one way of achieving it:
https://stackblitz.com/edit/github-2ta5y4?file=src%2FApp.vue