Home > front end >  How to restrict user to input only boolean in the Form?
How to restrict user to input only boolean in the Form?

Time:11-17

Is there a proper way where it restrict user to input only either true or false ? I saw that we can allow user to enter only number but how do we do for boolean ?

I tried following

<input
            type="boolean"
            [(ngModel)]="item.isApproved"
            class="form-control"
          />

But this allows user to enter any alphabet or numbers although I have defined the type is boolean.

CodePudding user response:

You can use :

<input
                type="checkbox"
                [(ngModel)]="item.isApproved"
                class="form-control"
              />

and If you want to make checkbox size bigger you can customize scss as :

input[type="checkbox"] {
  -ms-transform: scale(3);
  -moz-transform: scale(3);
  -webkit-transform: scale(3);
  -o-transform: scale(3);
  transform: scale(3);
  padding: 40px;
  box-shadow: 2em #3b88fd;
}

CodePudding user response:

You can use <input type="checkbox" /> to create a checkbox input that essentially only accepts boolean inputs:

<label>
  <input type="checkbox" />
  <span>A checkbox is either on or off - true or false</span>
</label>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related