Skip to content

Is it possible to link the number of elements in a ListElement to another element? #251

Answered by adamberecz
pwicks86 asked this question in Questions
Discussion options

You must be logged in to vote

Here's one way of achieving it:
https://stackblitz.com/edit/github-2ta5y4?file=src%2FApp.vue

<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)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pwicks86
Comment options

Answer selected by pwicks86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants