guggio
guggio

Reputation: 221

store form data from electron to dexiejs

I have an electron app with a form that will be used to get some information. I don't have an external server or url where I can sent the data, I need to get the form data and store them using dexie.js and vue that I'm using to intercept the click event on submit button. I'm not sure how I can save data, this because I need to get values from the form and then call dexie to store them, I'm using a vue method to manage the click, I was using the document.forms to get form elements name and value, but this is a bad approach. can anyone help me to find a way to achieve this?

//import Dexie from 'dexie';
const Dexie = require('dexie');
// Force debug mode to get async stacks from exceptions.
Dexie.debug = true; // In production, set to false to increase performance a little.

let db = new Dexie('clients');
db.version(1).stores({
  websites: "++id,client_name,hosting_provider,website_domain,panel_user,panel_pwd,db_host,db_name,db_user,db_pwd,wp_user,wp_pwd"
});


$(document).ready(function(){
  var myapp = new Vue({
    el: '#app',
    data: {
      message: 'Hello Vue!'
    },
    methods: {
      saveData(){
        //var form = document.getElementById('client-info') //document.forms;;
        var form = $('#client-info').serialize();
        console.log(form);
        //var formData = new FormData(form);
        //console.log(formData);
        // $.each( form[0].elements, function(i, index){
        //   console.log( index );
        //   console.log( form[0].elements[i].name, form[0].elements[i].value );
        //   // or make a new one
        //   db.clients.add({
        //          form[0].elements[i].name: form[0].elements[i].value
        //      });
        // });

        //console.log(Dexie);
        //console.log(db);
      }
    }
  });
  console.log(myapp);
});

NB: for now I've commented the code because it will not work, it don't save the data.

Upvotes: 1

Views: 369

Answers (1)

Melvin Witte
Melvin Witte

Reputation: 169

You might want to try adding the Dexie code to the main process, which acts as the backend in traditional web terms, and send the form via ipcRenderer to the main process (similar to what I proposed over here.

Upvotes: 1

Related Questions