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

93
Views
Generate uuid for input id

I want to generate random IDs for my input fields inside a v-for loop:

<div v-for="(data) in form" :key="data.attribute">
  <input type="date" :min="today" :id="_ + uuid()" :name="data.attribute" :placeholder="data.default_value" :readonly="data.render_type == 'readonly'" v-model="data.value" @input.prevent="updateOuter($event, data.refresh, 'due_date')"... 

using uuid:

const uuid = () => {
    return v4();
};

When now changing the input value the ID is getting changed every time cause uuid() is called. How would I generate fixed IDs for the input field using uuid? The form data object doesn't provide unique properties I could use cause elements could appear multiple times on the page.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think, you should create additional object like ids in data and generate uuid there like below;

<div v-for="(data) in form" :key="data.attribute">
  <input type="date" :min="today" :id="ids[data.attribute]" :name="data.attribute" />
</div>


{
  data(){
   const ids = form.reduce((res, item) => {
     res[item.attribute]= v4();
     return res;
   }, {});

   return {
     ids,

   }
  }
}
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!