jarvelov / vue-form-json-schema

Create forms using JSON schema. Bring your components!
https://jarvelov.gitbook.io/vue-form-json-schema/
353 stars 54 forks source link

How to work with Vuex model? #121

Closed mirestrepo closed 2 years ago

mirestrepo commented 2 years ago

Hi - I'm trying to use this package and have my model directly correspond to an object from my Vuex store. But it doesn't seem to work. Any ideas? I'm thinking it could be related to setter and getters...

Thanks in advance.

My code looks something like this - the first <b-input> works as expected, the one in the vue-form-json-schema does not.

<template>
  <div>
    <b-input v-model="sbatch[sbatchIndex].jobname"></b-input>
    <vue-form-json-schema
      v-model="sbatch[sbatchIndex]"
      :schema="schema"
      :ui-schema="uiSchema"
    ></vue-form-json-schema>
  </div>
</template>

<script>
import { mapMultiRowFields } from 'vuex-map-fields'
import VueFormJsonSchema from 'vue-form-json-schema/dist/vue-form-json-schema.esm.js'

export default {
  props: {
    sbatchIndex: {
      type: Number,
      required: true,
      validator: (value) => [0, 10].includes(value),
    },
  },
  components: {
    'vue-form-json-schema': VueFormJsonSchema,
  },
  data() {
    return {
      allEmailEvents: 0,
      isOpen: 0,
      state: {},
      //   model: { jobname: 'hello' },
      schema: {
        type: 'object',
        properties: {
          jobname: {
            type: 'string',
          },
        },
      },
    }
  },
  computed: {
    ...mapMultiRowFields(['sbatch']),
    uiSchema() {
      return [
        {
          component: 'input',
          model: 'jobname',
          fieldOptions: {
            class: ['form-control'],
            on: ['input'],
            attrs: {
              placeholder: 'Please enter your name',
            },
          },
        },
      ]
    },
  },
}
</script>

Thanks in advance!

mirestrepo commented 2 years ago

This was resolved.