QForm - Form Fields Generator



  • vue-form-json-schema supports any library. I’m testing it with Quasar now. It allows you to layout the UI as well so you don’t have a single ugly column for your forms too. Just all around butt-kicking. 🙂

    If you’re already using ajv for your schemas (if not you SHOULD) and lodash (who doesn’t), you’ll be happy to know this entire form generator weighs in at under 20kb gzipped, smaller than all other form generators, and with TONS more features! (see https://bundlephobia.com/result?p=vue-form-json-schema@2.5.3)

    github: https://github.com/jarvelov/vue-form-json-schema
    detailed docs with demos: https://jarvelov.gitbook.io/vue-form-json-schema/



  • WOW. Just… WOW. I spent a day testing vue-form-json-schema, and not only is it FULLY Quasar compatible, you can literally use this to create ENTIRE LAYOUTS not just a single Quasar form… HOLY COW is it powerful with Quasar… 🤯

    For anyone that would like to quickly use vue-form-json-schema with Quasar, here is some of my testing work… ☺

    Just “npm i vue-form-json-schema” in your Quasar project, create a component and paste this code into it…

    <template>
    <div class="">
       <vue-form-json-schema
        v-model="value"
        :schema="schema"
        :ui-schema="uiSchema"
        v-on:state-change="onChangeState"
        v-on:validated="onValidated"
        :components="components"
      />
    </div>
    
    </template>
    
    <script>
    import { QInput, QCard, QExpansionItem } from 'quasar'
    import VueFormJsonSchema from 'vue-form-json-schema/dist/vue-form-json-schema.esm.js'
    export default {
      props: ['value', 'schema', 'uiSchema'],
      components: {
        VueFormJsonSchema
      },
      data () {
        return {
          components: { // Add your sandboxed quasar or other components here (if you don't add it here, you can't use them)
            'input': QInput,
            'card': QCard,
            'expansion': QExpansionItem
          }
        }
      },
      methods: {
        onChange (value) {
          this.$emit('change', value)
        },
        onChangeState (value) {
          this.$emit('state', value)
        },
        onValidated (value) {
          this.$emit('valid', value)
        }
      }
    }
    </script>
    

    Then from anywhere in app, add this to your template (you’ll have to add the above component to your project as well of course):

    <form-generator v-model="yourModel" :schema="yourSchema" :uiSchema="yourUISchema"/>
    

    If you want some quick data that you can use to just see it working immediately, here is a q-card, with padding and spacing set, and inside it 2 input items, and they are all generated right from schema that you can put into config 🤯

    yourModel: {
            firstName: '', lastName: ''
          },
          yourSchema: {
            type: 'object',
            properties: {
              firstName: {
                type: 'string'
              },
              lastName: {
                type: 'string'
              }
            }
          },
          yourUISchema: [
            {
              component: 'card',
              fieldOptions: {
                class: ['q-ma-xl', 'q-pa-md']
              },
              children: [
                {
                  component: 'input',
                  model: 'firstName',
                  fieldOptions: {
                    on: ['input'],
                    props: { outlined: true, label: 'First Name' }
                  }
                },
                {
                  component: 'input',
                  model: 'lastName',
                  fieldOptions: {
                    props: { rounded: true, outlined: true, label: 'Last Name' },
                    class: ['q-pa-xl'],
                    on: ['input']
                  }
                }
              ]
            }
          ]
    


  • @njsteele Thank you for your example! It really is awesome with quasar.
    Do you know by any chance how/if the import of the quasar components can be skipped and ‘input’ be directly replaced with ‘q-input’?

              ...
              children: [
                {
                  #component: 'input',
                  component: 'q-input',
                  model: 'firstName',
                  fieldOptions: {
              ...
    

    Something simillar is done in the fourth example in the documentation but I cant get it to work with quasar in the same way.



  • @njsteele @gh7531 Thanks for your example. I started checking vue-form-json-schema for a project but couldn’t get it running. The default html UI elements work, but Quasar components dont.

    My code is as, what am I missing? : Note: I get an error in the browser console - Unknown custom element: <q-input> - did you register the component correctly.

    Failed to mount component: template or render function not defined - where is this to be added?

    <template>
      <q-page>
        <DynaFormComponent :model="model" :schema="schema" :ui-schema="uiSchema" />
      </q-page>
    </template>
    
    <script>
    import DynaFormComponent from 'vue-form-json-schema'
    import QInput from 'quasar'
    
    export default {
      name: 'vueform',
      components: {
        DynaFormComponent, QInput
      },
      data () {
        return {
          model: {},
          schema: {
            type: 'object',
            properties: {
              firstName: {
                type: 'string'
              }
            }
          },
          uiSchema: [{
            component: 'q-input',
            model: 'firstName',
            fieldOptions: {
              class: ['form-control'],
              on: ['input'],
              props: {
                type: 'text',
                placeholder: 'Type here'
              }
            }
          }]
        }
      }
    }
    </script>
    

    I have tried all possible combinations of component: ‘q-input’, component: ‘qinput’ etc. But cannot figure what I am missing.

    Any help is appreciated !

    Ty.



  • @Amod the error usually comes from the fact that the quasar component is not registered in the q.conf file.

    https://quasar.dev/quasar-cli/quasar-conf-js#Property%3A-framework

    if you’re not using Auto Import then you can do some thing like this:

    components: ['QInput','QTable','QFoobar']


  • @dobbel , Thanks for your reply.

    I am using - importStrategy: ‘auto’, and tried removing the QInput from the component. No luck yet.



  • @dobbel , Thanks for the pointer. It now works. What I had to change was:

    My import strategy was already auto, (though I can turn it off and use required components)

    but to get this to work I had to even set
    components: [‘QInput’] in the config file.

    The configuration file now looks like:

    framework: {
          iconSet: 'material-icons',
          lang: 'en-us',
          config: {},
          importStrategy: 'auto',
          components: ['QInput'], // added this
          plugins: []
        },
    

    It should have worked with importStrategy:auto in the first place. Right?



  • @Amod Yes I think you did everything right if you did not use the form-builder. What I think what went wrong in your case is that the form builder uses dynamic components and so not the q-input component explicitly in templates. So the ‘auto’ mode fails to see the need of importing q-input or whatever components the formbuilder creates.



  • My original post is quite old I have a much improved version of my form builder! as well as the app in general.

    9af3008d-ee90-4262-96ef-47908b3eb2df-image.png

    I did at one point try out vue-form-json-schema but it just didn’t fully meet my needs. One of the cool things my form builder is that it can use the values of one property in a schema instance as the option choices in another dynamically. Also I made it really easy to hide/show and have props of schema depend on the values of others. That you set in the schema. I really want to document and share this but just too preoccupied right now to do that. I have a major deployment coming up in the next week and after that I can put some attention to this if there is interest. In the meantime if you are savvy enough take a look at my repo of this project I am deploying that makes use of it. The component in question is Form.vue in the components subdirectory directory

    https://git.kebler.net/Light2/frontend/src/branch/master/src/components

    here are the schemas used. Notice they are in yaml format instead of json. This makes it WAY easier to comment stuff out and add comments. Of course they get read into a javascript object same as json.

    https://git.kebler.net/Light2/database/src/branch/master/schemas

    take a look at the config schema and page component. That is a simple single form implementation. The others are more complicated because they involved a collection of form instances.



  • @dgk Yes I would greatly appreciate if you took some time to document and share this new form builder with us!



  • @dgk Hi, your form builder repo is offline 😞


Log in to reply