简体   繁体   中英

How do I render a two worded value into the value attribute of an input tag (Express-Handlebars)

So I am rendering the handlebars page with the following code

router.get("/update", function(req, res) {
  mysql.pool.query("SELECT * FROM workouts WHERE id = ?",[req.query.id], function(err, rows, fields) {
    if (err) {
      console.log(err)
    } else {
      let parsedData = JSON.parse(JSON.stringify(rows))
      for (let data of parsedData) {
        if (data.lbs == 1) {data.lbs = "lbs"}
        else {data.lbs = "kg"}
        let formattedDate = (new Date(data.date)).toISOString().split('T')[0];
        data.date = formattedDate
        data.name = String(data.name)
      }
      let format = {
        input: parsedData
      }
      console.log("FORMAT", format)
      res.render("update", format)
     }
    })
})

The format variable has the following data in it

FORMAT { input: 
   [ { id: 48,
       name: 'teddy burger',
       reps: 22,
       weight: 45,
       date: '2020-12-08',
       lbs: 'kg' } ] }

My handlebars page is below

<h1 id="test123">Update This Entry!</h1>
 {{#each input}}
<form class="update-form" name="update" value="update" id="fitness-form">
    <input id="hidden-id" value={{this.id}} hidden>

    <label for="name">Name</label>
    <input id="name2" type="text" value={{this.name}} required><br>

    <label for="reps">Reps</label>
    <input id="reps2" type="number" value={{this.reps}} required><br>

    <label for="weight">Weight</label>
    <input id="weight2" type="number" value={{this.weight}} required><br>

    <label for="date">Date</label>
    <input id="date2" type="date" value={{this.date}} required><br>

    <label for="unit">Unit</label>
    <input id="unit2" type="text" value={{this.lbs}} placeholder="lbs or kg" required><br>
  
    <input id="submitUpdate" type="submit">
</form>
  {{/each}}

When I open the page in the browser though, it seems like anytime I pass in a name that is more than one word, it only grabs the first word and then the second one gets placed outside of the value like in the image below. Any suggestions? Thanks!! 在此处输入图像描述

Your value should have quotation marks " and "

value="{{this.name}}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM