Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load form data via REST into vue-form-generator

I am building a form, that needs to get data dynamically via a JSON request that needs to be made while loading the form. I don't see a way to load this data. Anybody out here who can help?

JSON calls are being done via vue-resource, and the forms are being generated via vue-form-generator.

export default Vue.extend({
  template,

  data() {
    return {
      model: {
        id: 1,
        password: 'J0hnD03!x4',
        skills: ['Javascript', 'VueJS'],
        email: '[email protected]',
        status: true
      },

      schema: {
        fields: [
          {
            type: 'input',
            inputType: 'text',
            label: 'Website',
            model: 'name',
            maxlength: 50,
            required: true,
            placeholder: companyList
          },
        ]
      },

      formOptions: {
        validateAfterLoad: true,
        validateAfterChanged: true
      },
      companies: []
    };
  },

  created(){
    this.fetchCompanyData();
  },

  methods: {
    fetchCompanyData(){
      this.$http.get('http://echo.jsontest.com/key/value/load/dynamicly').then((response) => {
        console.log(response.data.company);
        let companyList = response.data.company; // Use this var above
      }, (response) => {
        console.log(response);
      });
    }
  }

}); 
like image 975
MapDev Avatar asked Oct 17 '22 19:10

MapDev


1 Answers

You can just assign this.schema.fields.placeholder to the value returned by the API like following:

  methods: {
    fetchCompanyData(){
      this.$http.get('http://echo.jsontest.com/key/value/load/dynamicly').then((response) => {
        console.log(response.data.company);
        this.schema.fields.placeholder = response.data.company
      }, (response) => {
        console.log(response);
      });
    }
  }
like image 83
Saurabh Avatar answered Oct 27 '22 11:10

Saurabh