Tips for handling form submissions within an Electron application on your desktop

I came across this question, but I'm still struggling to understand the best approach to handling forms in Electron. I am currently using the code snippet below and aiming to utilize dexie.js to store the form data upon submission. However, I'm facing challenges in retrieving the data when using Vue.

The code in my main process file looks like this:

// main.js
const electron = require('electron');
const { app, BrowserWindow, ipcMain } = electron;

function createWindow(){
  let win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  });
  win.loadFile('index.html');

}
app.whenReady().then(createWindow);

ipcMain.on('submitForm', function(event, data) {
   // Access form data here
   console.log(data);
});

Here is the code used in my renderer:

// renderer.js
const ipcRenderer = require('electron').ipcRenderer;

const Dexie = require('dexie');
// Enabling debug mode to get async stacks from exceptions.
Dexie.debug = true; // For production, set to false for better performance.

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: {
      submitForm(){
        ipcRenderer.send('submitForm', formData);
      }
    }
  });
  console.log(myapp);
});

And this is the HTML defining the UI:

<!-- index.html -->
<div class="container-fluid p-4" id="app">
  <div class="row">

    <div class="col-8 card p-4">
      <form id="client-info" v-on:submit.prevent="submitForm()">
        <div class="form-row">
          <div class="col-12">
            <h4>Client Information</h4>
          </div>
          <div class="col-6">
            <label for="">Client:</label>
            <input type="text" class="form-control" id="client-name" name="client_name" placeholder="">
          </div>

          <!-- More form fields omitted for brevity -->

          <button type="submit" class="btn btn-success">SAVE</button>
        </div>
      </form>
    </div>

    <div class="col-4">
      <ul class="nav ml-auto">
        <li class="nav-item">
          <a class="nav-link" href="#">{{ message }}</a>
        </li>
      </ul>
    </div>

  </div>
</div>
<script src="renderer.js"></script>

Note: I intend for the col-4 section to display a list of clients' names, which align with the form data, sourced from my dexie.js database.

Answer №1

Apologies for the previous incorrect response. I mistakenly confused IndexedDB with a different relational backend database. For a simple working example of using Dexie with electron, you can refer to the sample code available at https://github.com/dfahlander/Dexie.js/tree/master/samples/electron

Correction: The information provided below is INCORRECT!

If you intend to implement Dexie in the backend (main process), you would need to add the following code:

// main.js
const electron = require('electron');
const { app, BrowserWindow, ipcMain } = electron;

const Dexie = require('dexie');
// Enable debug mode to capture asynchronous stacks from exceptions.
Dexie.debug = true; // For production environments, set to false for better performance.

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"
});

function createWindow(){
  let win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  });
  win.loadFile('index.html');

}
app.whenReady().then(createWindow);

ipcMain.on('submitForm', function(event, data) {
  // Ensure that the data follows the correct format
  // It should be an object with key-value pairs corresponding to the websites table you created
  db.add(data)
  console.log(data);
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Keep the user on the current page even after submitting the parameter

I have a situation where I am loading a page into a specific div. This loaded page contains a link that includes a parameter which directs to another page for deletion. However, when I click on the loaded page within the div, it redirects me to the deletio ...

Style the div element with CSS

Is there a way to style a div element within an HTML document using Sencha framework? I have specific CSS properties that I would like to apply to my div. #logo{ position:absolute; top:20%; left:0%; } Below is a snippet of my Sencha code: Ex ...

the dropdown menu toggle is not working as expected

My dropdown icon is not appearing and the menu options are not functioning properly. Despite trying to use a script to display the text when an option is clicked, it doesn't seem to be working. It appears that the toggle functionality is not working ...

Establish a universal default component for Vue route configurations

How can I load the component of a specific route in my Vue application within a global component? For example, is there a way to set a global component that will display the components of all routes? I have a Frontend.vue file with <router-view>< ...

The ExpressJS middleware is executing twice

I'm experiencing an issue with the following code snippet. When I include the middleware logger() as the first argument to app.use(), it is called twice. However, when I place it as the second argument, it doesn't get executed at all. Can anyone ...

Use VueJS to input numeric values and upon pressing the button, dynamically redirect to a specific link based on

I am currently working on a project where I need to bind an input field with the v-model directive. My goal is to pass the numbers entered in this field to a button, so that upon clicking it can redirect to another page using the entered numbers. This is ...

Clear out a collection in backbone.js

I am looking to clear out a collection by removing each item in sequence. this.nodes.each(function(node){ this.nodes.remove(node); }, this); The current method is ineffective as the collection length changes with each removal. Utilizing a temporary arr ...

Develop React routes on the fly

Currently, I am working on a React App that requires the creation of Routes dynamically based on data models sent by the backend in JSON format. For example: { "Route1": [ { "id": 1, "visible": true, "other_data": "..." } ], "Route3": [ { "i ...

Struggling to grasp the concept of PHP LZW decompression function within JSend framework

I am currently working on converting the LZW decompressor from PHP to JavaScript and I have encountered a function that is giving me some trouble. function decompressLZW(aCodes) { var sData = ''; var oDictionary = []; for (var i = 0; i &l ...

Submit form using jQuery after making an AJAX request with jQuery's $

I'm working on the following code: $.get(link, function(data, status) { document.getElementById("test").value = data; }); $('#formtest').submit(); Everything works fine in Firefox, but in Google Chrome the submit is done before t ...

Angular Validation displays ng-valid when the form is actually invalid

I am currently working on a wedding RSVP form https://i.stack.imgur.com/Ct8Ux.png My objective is to hide the DONE submit button and only display it when the form is considered valid. <form method="POST" action="http://l.bheng.com:8888/wedding" acce ...

Having trouble displaying results in Vue.js after making an API request?

I am facing challenges in displaying the results using vue.js. The data from my API (ASP.NET CORE) is being retrieved successfully, as shown in my vue dev tools on Google Chrome. However, I am encountering difficulties in rendering the results on the brows ...

Incorporate CloudKit JS into Vue Application

I want to integrate CloudKit JS into my new Vue project so I can access its functions from any component within my app. As a newcomer to Vue, I appreciate your patience with me. :) Currently, I attempted adding the following code snippet in main.js: var ...

When dealing with errors in fetching JSON data, consider implementing a robust error handling strategy and

Is there a way to provide a fallback JSON string in case the fetch URL fails to connect? const Response3 = await fetch(`https://example.com/match/get?_=&id=${matchlist[2].id}`) ...

Update the second mouse click functionality using jQuery

I currently have a jQuery function integrated into my WordPress portal that manages the functionality of the menu and the display of subcategories to ensure proper mobile optimization. This code, which was created by the theme editor, handles these aspects ...

The post request was successful, but unfortunately it redirected to an error page

Encountering an unusual problem while executing a POST request. There are three different forms on the same page, all with a post method. The first form functions correctly. However, the other two forms encounter an issue: upon clicking the save button, i ...

Exploring the iteration of JSON objects within an array using AngularJS

My auto search module has the following JSON structure. I need to iterate through an array of JSON objects and use keys and values as required. I have attempted the code below. However, with the provided JSON object, I am able to retrieve the key but not ...

Issue with transferring JQuery variable to JavaScript

Using JQuery, I am attempting to retrieve a variable from PHP located at a specific URL and then utilize that variable in JavaScript to modify the content on the webpage. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">& ...

What's the best way to vertically center a div with a 100% width and a set padding-bottom on the screen?

I am struggling with positioning the following div on my webpage. .div { width:100%; padding-bottom:20%; background-color:blue; } <div class="div"></div> I have been searching for a solution to vertically center this responsive div on my web ...

Styling nested divs in CSS

I am experiencing an issue where the child divs within parent divs are overflowing outside of the parent divs. To get a better understanding of the problem, please try running the code below in a browser: My goal is to align the innermost divs horizontall ...