Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change input -> change checkbox model without click

If you update text input model "sg.Value", checkbox shoud be checked, but model "sg.AnswerId" is not set.

Sample

How to get:

Change text input -> Set checkbox model ?

<label>
  <input type="checkbox"
         ng-model="sg.AnswerId"
         ng-true-value="'{{answer.Id}}'"
         ng-checked="sg.Value != undefined"
         >
  <input type="text"
         placeholder="Your text"
         ng-model="sg.Value"
         >
</label>

Checkbox must become checked and it's model updated, when i typing in input.

like image 310
WaNgeL Avatar asked Oct 21 '15 11:10

WaNgeL


1 Answers

My solution is plunkr

Listener on input change:

function trackInput(){
  if(sg.Value !== '' && sg.Value !== undefined) {
    sg.AnswerId = sg.answer.Id;
  } else {
    sg.AnswerId = false;
  }
};

Maybe anyone have better solution? Share please.

like image 184
WaNgeL Avatar answered Sep 25 '22 15:09

WaNgeL