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

150
Views
How to set default v-model value from HTML?

I'm using twig with vue.js and I need to render dynamic form dependent on fields list returned from twig. Main problem here is that I cant pass fields list in Vue.js script and need to set default value from html

Input looks like this( {{ }} is twig brackets, not vue.js)

id="{{ id }}_input"
class="{{ id }}_input {{ type }}_input"
label="{{ label ?? null}}{{ meta.required ? " *" : null }}"
name={{ name }}
value={{ default ?? null }}
v-model="inputs['{{ id }}']"

I tried to do something like this

:inputs['{{id}}'] = "{{ default }}"

:inputs.{{id}} = "{{ default }}"

With no success. I also tried to map inputs keys on mount and get input values with document.getElementById, but inputs variable is always empty. Also I tried to get all form inputs on mount like this

 this.$el.querySelectorAll('input')

but in such case input value is always empty.

At this moment I'm using this hack, but this is absolutely awful imo, is there any other way to do it?

input

tmpValue="{{ default ?? null }}"

Vue.js

mounted() {
  this.$el
      .querySelectorAll('input')
      .forEach(input => {
          input.value = input.getAttribute('tmpValue')
          input.dispatchEvent(new Event('input'))
      });
}
about 4 years ago · Juan Pablo Isaza
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!