jeudi 17 octobre 2019

Checkbox Checked always Post True or False in Angular 8

Problem

POST/GET Request

      field_name : true/false

What i need

POST/GET Request

 field_name : Y/N

Test Component html

    <input id="field.code" [formControlName]="field.code" class="form-check-input" type="checkbox"
       value= [checked]="N"
           [(ngModel)]="isChecked"
          (change)="checkCheckBoxvalue(isChecked?'Y':'N')"/>


      export class Component implements OnInit {

            checkCheckBoxvalue(event: any) {
             if (event) {
            this.test = event;
                   }
              }

Function checkCheckBoxvalue gives correct value that if checked 'y' or unchecked to 'N'

if we set value change from checkCheckBoxvalue function Y Or N it still post True or False

problem is

 value="N" [checked]="N"
  value="Y" [checked]="Y"

POST value always in true or false

Output after POST Request

    FORM DATA
    pref_key: false
    button_key: save

Any suggestion is most welcome.




Aucun commentaire:

Enregistrer un commentaire