jeudi 23 juin 2016

how to check multiple checkbox is checked

<input type="checkbox" name="sportId" ng-required="!sportId" data-checklist-model="player.sport_id" data-checklist-value="role.id" ng-click="myFunction(role.id)" ng-change="stateChanged(player.sport_id)">

    $scope.roles = [
    {id: 1, text: 'Hockey'},
    {id: 2, text: 'Soccer'},
    {id: 3, text: 'Lacrosse'},
    {id: 4, text: 'Golf'},
    {id: 5, text: 'Football'},
    {id: 6, text: 'Other'}
  ];

i have used this method it works good bt it work for single checkbox if you i select multiple checkbox it doesn't check correctly

reason why because when i click one checkbox it has none value in array when i unchecked it has first id. So in the other end if i select 1st (none value in array hence response correct) if i click and select 2nd id (it has one 2 value true) then it says uncheck

how to check multiple checkbox is checked

$scope.stateChanged = function(changedSport){

        if($scope.player.sport_id == false)
        {
          alert("Checked");

        }else{
          alert("unChecked");


   } 




Aucun commentaire:

Enregistrer un commentaire