Node Express Jade - Checkbox boolean value

后端 未结 5 693
青春惊慌失措
青春惊慌失措 2021-01-19 01:55

I\'m using Node+Express+Jade to render some webpages. On a form there are 2 checkboxes. When the form is submitted through POST, if the checkbox is checked, I get req.

5条回答
  •  梦谈多话
    2021-01-19 02:41

    If your default value is false then this solution seems the most straight-forward to me. First set a default with your DB/ORM. I'm using Mongoose so in the model file it's:

    published: { type: Boolean, default: false },
    

    Then in the form input element set the value to true:

    
    
    

    By unchecking it you'll submit an empty value which defaults back to false.

提交回复
热议问题