Reputation: 163
I have one button called test and one drop-down menu with three values. How to enable-disable Test button according to value selected in drop down menu. Eg. If selected "Not Ready" , button should disable If selected Ready or Attention, button should enable
<div class="row">
<div>
<button id="testBtn" class="btn btn-default" >Test</button>
</div>
</div>
<div class="row">
<div class="col-md-12">
<select name="select">
<option value="value1" selected>Not ready</option>
<option value="value2">Ready</option>
<option value="value3">Attention !!</option>
</select>
</div>
</div>
See Plunker
Upvotes: 0
Views: 19313
Reputation: 767
<select ng-model="item" ng-options="a.name for a in data">
<option value="">
select
</option></select>
<button class="btnS btn-success ctrl-btn" ng-click="save()" ng-disabled="!item"> Submit</button>
Upvotes: 1
Reputation: 20168
If the validation value is number then use this method.
<div class="form-group">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<label class="control-label col-xs-4 col-sm-4 col-md-4 col-lg-4">User Type</label>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
<select class="form-control height_30" ng-model="data1.user_type " ng-options="cust.id as cust.typename for cust in usertype"></select>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<label class="control-label col-xs-4 col-sm-4 col-md-4 col-lg-4">Password</label>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
<input type="text" class="form-control" ng-model="data1.user_passwd">
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<label class="control-label col-xs-4 col-sm-4 col-md-4 col-lg-4">Customer</label>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
<select ng-disabled="data1.user_type === 1 || data1.user_type === 2" class="form-control height_30" ng-model="data1.customer_id" ng-options="cust.customer_id as cust.customer_name for cust in customers"></select>
</div>
</div>
</div>
</div>
Upvotes: 1
Reputation: 4014
You need an Angular app and controller. From there you can bind a model to your select, and then use an expression with the ng-disabled directive on the button to enable and disable it dynamically depending on the value in the box. See below. ng-model on the select binds it to $scope.currentState which is what I compare my literal string against in the ng-disabled directive on the button.
var app = angular.module('myapp', []);
app.controller('MainCtrl', function($scope) {
$scope.states = ['Not ready', 'Ready', 'Attention !!'];
$scope.currentState = 'Not ready';
});
<!DOCTYPE html>
<html ng-app="myapp">
<head>
<meta charset="utf-8" />
<title>AngularJS App</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="MainCtrl">
<div class="row">
<div>
<button id="testBtn" class="btn btn-default" ng-disabled="currentState === 'Not ready'">Test</button>
</div>
</div>
<div class="row">
<div class="col-md-12">
<select name="select" ng-model="currentState" ng-options="state as state for state in states">
</select>
</div>
</div>
</body>
</html>
Upvotes: 5