Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
How can I submit dynamic form since i don't know my v-models

I have a dynamic form, I render my components ( input component, textarea components...) depends on what i have in my database table, I would like to know how can i submit the form since i don't know the names of my v-models because each user in my application can make a different form.

<template>
    <b-modal id="modal-1" v-model="showModal" title="Add Contact" modal-class="right" content-class="rounded-0" @ok="handleOk" @hidden="resetModal">
        <form ref="form" name="addcontact">
            <render :definition="response"></render>
        </form>
    </b-modal>
</template>

<script>

import render from "../../components/forms/dynamic-render";

export default {
    components:{
        render
    },
    data() {
        return {
           showModal: true,
           response: [
               {type:'text', label: 'My title', is_required:1},
               {type:'textarea', label: 'text zone'}
           ]
        }
    },
    methods:{
        resetModal: function(){
            this.$emit('close');
        },
        handleSubmit: function($e){
            // i want to submit using axios but I don't know how in this case ( dynamic form with different v-model value ) 
        },
        handleOk: function(bvModalEvt){
            
            this.handleSubmit();
        }
    }
};
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I don't know the names of my v-models because each user in my application can make a different form.

You don't need to know the name. Moreover, You only need the data that the user provides.

The solution that I've provided to you is to get the data from the render component:

1st, You need to bind all the form input, textarea, and select elements to a Json Object

Such as

<template>
  <p>Assume a complex dynamic layout</p>
</template>
<script>
export default {
  name: 'render',
  data () {
    return {
    /* bind all the  input, textarea, and select elements to the Item object */
      Item: {
        foo: 'foo',
        bar: 'bar'
      }
    }
  },
  methods: {
    EnvelopeItem: function () {
      return JSON.stringify(this.Item)
    }
  }
}
</script>

2nd, define a method to have access to the Item from the parent component (EnvelopeItem)

3rd, assign a reference (ref) to the render component

<render ref="render" :definition="response"></render>

4th, call the EnvelopeItem from the parent component via the render reference

handleSubmit: function ($e) {
  let json = this.$refs.render.EnvelopeItem()
  console.log(json)
  // i want to submit using axios but I don't know how in this case ( dynamic form with different v-model value )
}

All done.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!