mardi 27 décembre 2016

How to enabled/disabled submit button based on checkboxes?

I want to enable submit button when one or more checkbox value is selected , i tried with below code its enabling button but if i check one value its making all checkbox seletced ? Any idea what is implemented wrong ?

main.html

<tr ng-repeat="user in userList track by $index">
          <td st-ratio="20"></td>
          <td st-ratio="30"> </td>
          <td st-ratio="20"><input type="checkbox" ng-model="userList.selected" ng-click="checkedValue(user)"> </td>
        </tr>

 <button class="btn btn-primary" ng-disabled="user.selected" ng-disabled="!userList.selected" ng-click="addUsers()">Add User(s)</button>

Ctrl.js

$scope.$on('show-user-list',function(e,data){
    $scope.userList = data;
    $scope.userList.selected = false;
  });


 $scope.checkedValue = function(user) {
 user._id = user.attuid;
 user.type = 'user';
        if ($scope.selectedUsers.indexOf(user) === -1) {
            $scope.selectedUsers.push(user);
            $scope.userList.selected = true;
        } else {
            $scope.selectedUsers.splice($scope.selectedUsers.indexOf(user), 1);
        }
        console.log($scope.userList.selected);
    };




Aucun commentaire:

Enregistrer un commentaire