user1183194
user1183194

Reputation: 137

How to take value of a checkbox as 1 for checked box in jade

I am using jade in which I have a checkbox in my code. When user selects a checkbox then value is send as true to the server instead of 1 while for unchecked boxes value is sent as 0. How can I pass value of checkbox as 1 when user checks the checkbox.

input.form-control(type="checkbox", name="compare_form_required", id="compare_form_required", ng-model="program.compareFormRequired")

Upvotes: 0

Views: 908

Answers (3)

  1. if(Check=="on")
  2. label(for=key)= "IVA "
  3. Input(name="iva" type="checkbox" id=key onchange="ivaSwitch(this.id)" checked)
  4. else
  5. label(for=key)= "IVA "
  6. Input(name="iva" type="checkbox" id=key onchange="ivaSwitch(this.id)" )

Upvotes: 0

user1183194
user1183194

Reputation: 137

I Used ng-true-value="1" that sets the value as 1 on check of a checkbox So I have used it this way :

input.form-control(type="checkbox", name="compare_form_required", id="compare_form_required", ng-model="program.compareFormRequired", ng-true-value="1")

Upvotes: 1

brnrd
brnrd

Reputation: 3486

I think there is no way to do so in jade, you can only do something like this afterwards to convert it :

var data = request.body;
if (data.yourCheckbox === 'on') {
  data.yourCheckbox = 1;
} else if (data.yourCheckbox) {
   data.yourCheckbox = 0;
}

Upvotes: 0

Related Questions