Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to disable button when text of input and table equal

<div ng-app="myApp" ng-controller="myCtrl">

 <input type="button" ng-click="add()" value='Add'  ng-model="button" >

<table id="tb"  >

<tr ng-repeat="x in bimar">


   <td><div class="danger" ng-if="x.name==new.name">{{x.error}}</div>  </td>
</tr>

</table>


What I have tried:

<!DOCTYPE html>
<html>
<style>
#tb{padding:10px;background-color:#DAF7A6;}

#tb tr {padding:5px 20px;font-size:20px;background-color:#FFE633;}
.green{background-color:red;}
.yellow{background-color:blue;}
.danger{background-color:red;}

</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
 نام بیمار  <input type="text" name="name" ng-model="new.name" ><br>
 تاریخ مراجعه  <input type="text"  name="date" ng-model="new.date " ><br>
 زمان مراجعه  <input type="text" name="time" ng-model="new.time" ><br>
 <input type="button" ng-click="add()" value='Add'  ng-model="button">

<table id="tb"  >
<thead>
<td>ردیف</td><td>نام بیمار</td><td>تاریخ مراجعه</td><td>زمان مراجعه</td>
</thead>
<tr ng-repeat="x in bimar">

   <td>{{$index+1}}</td>
   <td >
   {{x.name}}
   </td>
 
   <td  ng-class="colorClass" >{{x.date}}</td>
   <td  ng-class="colorClass">{{x.time}}</td>
   <td><div class="danger" ng-if="x.name==new.name">{{x.error}}</div>  </td>
</tr>

</table>

<p ng-class="colorClass" >I should be either green or blue!</p>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.bimar =[
       {"name":"john","date":"11/11/97","time":"8:20","error":"flase"},
       {"name":"daniel","date":"15/10/97","time":"9:20","error":"flase"},
       {"name":"mick","date":"11/10/97","time":"9:20","error":"flase"}
    ];

     

    $scope.add=function(){
  
  
               $scope.bimar.push($scope.new); 
                
        $scope.new={}; 
    
   
    }
});



	
</script>



</body>
</html>
Posted
Updated 28-Jan-19 17:33pm

1 solution

You can use a function to check whether the new name exists in the array and disable button based on that,

$scope.valid = function(){
          $scope.disable = $scope.bimar.some(t=>t.name==$scope.new.name);
}


Plunker[Demo]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900