Create a personalized and distinct name following the submission of data into multiple text fields either through Nuxt/Vue or by utilizing pure JavaScript

In my new app, users can register packages and then participate in a ballot session where the package will be assigned to someone else. To make this process smoother, I want each ballot session or box to have a unique Ballot ID attached to it.

For example, let's say we have a package named Keyboard with the code KBD01. It is in ballot session No. 5, inside ballot box No. 2.

The user will need to input three different values:

  1. text input 1: 5

  2. text input 2: 2

  3. text input 3: KBD01

Based on these inputs, a unique name for the ballot box will be generated. Clicking input 4 will display 5-2-KBD01. This unique ID will be saved to Firestore Firebase for reference during the ballot session.

I'm looking for guidance on how to achieve this using Nuxt/Vue with Vuetify or even just plain JavaScript.

<v-col cols="12" sm="6" md="6">
    <label>Assign Ballot Session</label>
    <v-select
        outlined
        v-model="BallotSession"
        :items="BallotSessionItems"></v-select>
</v-col>
<v-col cols="12" sm="6" md="6"></v-col>
<v-col cols="12" sm="6" md="6">
    <label>Ballot Box No.</label>
    <v-text-field
        outlined
        v-model="BallotBox"></v-text-field>
</v-col>
<v-col>
    <label>Package Code</label>
    <v-text-field
        outlined
        v-model="PackageCode"
        @blur="generateBallotID"></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="6">
    <label>Ballot ID</label>
    <v-text-field
        outlined
        v-model="BallotID"></v-text-field>
</v-col>
data: () => ({
    BallotSession: '',
    BallotBox: '',
    PackageCode: '',
    BallotID: '',
}),

methods: {
    generateBallotID() {
      // This is the part where I need assistance to implement the unique ID generation.
    }
}

Answer №1

If I understood correctly:

new Vue({
  el: '#demo',
  vuetify: new Vuetify(),
  data() {
    return {
      BallotSession: '',
      BallotBox: '',
      PackageCode: '',
      BallotID: '',
      BallotSessionItems: [5,6,7]
    }
  },
  methods: {
    generateBallotID() {
      if (this.BallotSession && this.BallotBox && this.PackageCode) {
        this.BallotID = this.BallotSession + '-' + this.BallotBox + '-'+ this.PackageCode
      }
    }
  }
})

Vue.config.productionTip = false
Vue.config.devtools = false
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="13656676677a756a53213d6b">[email protected]</a>/dist/vuetify.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2b4b7a782f0ecba">[email protected]</a>/dist/vue.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f797a6a7b6669764f3d2177">[email protected]</a>/dist/vuetify.js"></script>
<div id="demo">
<v-app>
      <v-main>
      <v-container>Hello universe
  <v-col cols="12" sm="6" md="6">
      <label>Assign Polling Session</label>
      <v-select
          outlined
          v-model="BallotSession"
          :items="BallotSessionItems"
          @change="generateBallotID"></v-select>
  </v-col>
  <v-col cols="12" sm="6" md="6"></v-col>
  <v-col cols="12" sm="6" md="6">
      <label>Ballot Box No.</label>
      <v-text-field
          outlined
          v-model="BallotBox"
          @blur="generateBallotID"></v-text-field>
  </v-col>
  <v-col>
      <label>Object Code</label>
      <v-text-field
          outlined
          v-model="PackageCode"
          @blur="generateBallotID"></v-text-field>
  </v-col>
  <v-col cols="12" sm="6" md="6">
      <label>Poll ID</label>
      <v-text-field
          outlined
          v-model="BallotID"></v-text-field>
  </v-col>
  </v-container>
  </v-main>
    </v-app>
</div>

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

leveraging socket.io alongside express router

As someone who is relatively new to node.js, I am currently in the process of creating a webchat application. My project consists of a server.js file and a router.js file where I have defined all my routes. Unlike many others, I am not using express-genera ...

Exploring Opencascade.js: Uncovering the Real Text within a TCollection_ExtendedString

I am currently attempting to retrieve the name of an assembly part that I have extracted from a .step file. My method is inspired by a blog post found at , however, I am implementing it using javascript. I have managed to extract the TDataStd_Name attribut ...

Attempting to invoke a promise within a function yields an error message stating that it lacks call signatures

Recently, I came across this interesting class: export class ExponentialBackoffUtils { public static retry(promise: Promise<any>, maxRetries: number, onRetry?: Function) { function waitFor(milliseconds: number) { return new Pr ...

Displaying selected checkbox values in a URL with parameters using PHP and JavaScript

I am looking to extract the selected checkbox value and append it to the browser URL with a parameter name. Below is my HTML code: <div style="width:200px; float:left"> Price <div> <input type="checkbox" name="price" value="0-1 ...

What is the best way to pass a prop into the <router-link>?

If I replace this {{ name }}, the result is "campaigns" Now, I want to use that in my link <router-link :to="'/' + '123' + '/' + item.id"> {{ item.name }}</router-link> I attempted to substitute '1 ...

Utilizing API data to set the state in a React component

In my quest to modify the state of this React component, I have a variable called rankAndTeam that holds the "prints=>" data listed below. My goal is to assign "Washington Capitals" to this.state.teamRank["0"], "New York Islanders" to this.state.teamRan ...

Can I modify individual properties of xAxis.labels in HighCharts?

I am seeking to customize the properties of my labels on the x-axis in a unique way (View my query here). I have a clear understanding of how to achieve this for dataLabels: See API reference. This process is akin to what has been explained here. Howeve ...

Confirmation dialog with user-defined button text

When the confirm prompt box is used, it typically displays "ok" and "cancel" buttons. I am looking to customize the label text for the buttons to read as Agree and Not Agree instead. If you have any suggestions on how to achieve this modification, please ...

What are the risks and drawbacks of revealing your environment variables to the browser in NextJS?

Currently in the process of setting up Firebase v9 authentication within a NextJS application I am developing. Initially, I attempted to utilize Next's server-side environmental variables for my Firebase configuration but encountered issues with all e ...

Middleware for enabling the Cross-Origin Resource Sharing (CORS) functionality to efficiently manage preflight

My CORS configuration is set up globally to handle credentials like this: app.use(cors({ origin: 'https://example.com', credentials: true })) However, there are certain routes where I need to allow OPTIONS requests. Following the documentation, ...

Guide to Sending and Scheduling Notifications through HTML 5's Notification Web APIs

Is it possible to utilize Web APIs to Schedule Notifications and send them at specific times? I am working on a CMS application that allows users to schedule and send push notifications for their mobile apps. I am interested in implementing something sim ...

sequencing the compilation of Node.js modules

I am facing an issue with my node application involving multiple interdependent modules exported using module.exports. These modules include mongohelper, transaction, server, conhandlr, and appmin. Compile order- mongohelper transaction server (..the ...

What is the best method for starting a string using the symbol '~'?

Hello everyone! I have a task that requires me to add a special feature. The user needs to enter something in a field, and if it starts with the tilde (~), all subsequent entries should be enclosed in a frame within the same field or displayed in a list ...

After using `setAttribute`, React is unable to produce any audio

Currently, I am facing an issue with a React component where it should play sound from an array of IDs stored in the database by setting the ID to the src attribute for the source tag. However, this functionality is not working as expected. Interestingly, ...

The document ready event does not fire upon page load, but can be triggered using the Developer Tools Console

When the ajax call is successful, the li element gets added to the ul. $.ajax({ .. success: function (response) { response.data.forEach(function (x) { $("#ulMain").append('<li class="liSub">' + x + &apo ...

Customize each Picker.Item element in React Native with unique styles

How can I style individual Picker.Items beyond just changing the text color? Additionally, what other props can be used for a Picker.Item? I am aware of "key", "value", "label", and "color". Are there any additional props available? I want to customize o ...

Exploring the power of Vue CLI service in conjunction with TypeScript

I've recently set up a Vue project using the Vue CLI, but now I am looking to incorporate TypeScript into it. While exploring options, I came across this helpful guide. However, it suggests adding a Webpack configuration and replacing vue-cli-service ...

Tips on utilizing a function that was generated within the constructor

I'm currently in the process of developing a function within the constructor, and it is essential that this function be placed inside the constructor. I am interested in implementing a button to trigger this function from an external source, but unfor ...

Utilizing promise values within asynchronous functions

I know this question has been asked multiple times, but I'm facing a situation where I need to retrieve a variable created within a promise. The examples I've come across involve using .then to access the data, but in my case, I need to work with ...

Discovering a way to monitor keyup and keydown occurrences in JavaScript on an iPhone

Looking to track keyup/keydown events in JavaScript on iPhone browsers. My goal is to automatically move the focus to the next form element after the user has inputted the maximum number of characters in a text box. ...