Make Fields disabled based on DropDownList Selection using AngularJS

Last Reply 7 months ago By dharmendr

Posted 7 months ago

Hi,

I have one grid view with fields

I have one dropdoown with relevant values like below

1)Dropdown 2)DatePicker  3)Textbox

1)If i can select dropdown i need to disable  column Date

2)If i can select datepicker i need to disable 3 columns (FromTable,

DisplaycName,ValueCName) 

3)If i can select textbox need to disable all the coulms (Date,

FromTable, DisplaycName,ValueCName)

Could you please check it and help me

    <table id="tblOrders" class="table table-responsive">
        <tr>
            <th>Cname</th>
            <th>Ctype</th>
            <th>From Table</th>
            <th>DisplayCName</th>
            <th>ValueCName</th>
            <th>Date</th>
        </tr>
        <tbody ng-repeat="detail in Details">
            <tr>
                <td>{{detail.CName}}</td>
                <td>
                    <select ng-model="detail.CType" class="form-control">
                        <option value="audi" selected>Select value</option>
                        <option value="Dropdown">Dropdown</option>
                        <option value="Textbox">Textbox</option>
                        <option value="DatePicker">DatePicker</option>                    
                    </select>
                </td>
                <td><input type="text" class="form-control" ng-model="detail.FromTable" /></td>
                <td><input type="text" class="form-control" ng-model="detail.DisplayCName" /></td>
                <td><input type="text" class="form-control" ng-model="detail.ValueCName" /></td>
                <td>
                    <select ng-model="detail.Date" class="form-control">
                        <option value="Today" >Today</option>
                        <option value="Lastday">Lastday</option>
                    </select>
                </td>
            </tr>
        </tbody>
    </table>

 

Posted 7 months ago

Hi mahesh213,

Check this example. Now please take its reference and correct your code.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.js"></script>
<script type="text/javascript">
    var app = angular.module("MyApp", []);
    app.controller("MyController", function ($scope, $filter) {
        $scope.Details = [{ CName: "Fromdate", CType: 'audi', FromTable: '', DisplayCName: '', ValueCName: '', Date: '' },
                            { CName: "Todate", CType: 'audi', FromTable: '', DisplayCName: '', ValueCName: '', Date: ''}];
        $scope.TypeChange = function (cType, cName) {
            for (var i = 0; i < $scope.Details.length; i++) {
                if ($scope.Details[i].CName == cName) {
                    if (cType == "Dropdown") {
                        $scope.Details[i]["isDisabledDate"] = true;
                        $scope.Details[i]["isDisabledFromTable"] = false;
                        $scope.Details[i]["isDisabledDisplayCName"] = false;
                        $scope.Details[i]["isDisabledValueCName"] = false;
                    } else if (cType == "DatePicker") {
                        $scope.Details[i]["isDisabledFromTable"] = true;
                        $scope.Details[i]["isDisabledDisplayCName"] = true;
                        $scope.Details[i]["isDisabledValueCName"] = true;
                        $scope.Details[i]["isDisabledDate"] = false;
                    } else if (cType == "Textbox") {
                        $scope.Details[i]["isDisabledFromTable"] = true;
                        $scope.Details[i]["isDisabledDisplayCName"] = true;
                        $scope.Details[i]["isDisabledValueCName"] = true;
                        $scope.Details[i]["isDisabledDate"] = true;
                    } else {
                        $scope.Details[i]["isDisabledFromTable"] = false;
                        $scope.Details[i]["isDisabledDisplayCName"] = false;
                        $scope.Details[i]["isDisabledValueCName"] = false;
                        $scope.Details[i]["isDisabledDate"] = false;
                    }
                }
            }
        }
    });
</script>
<div ng-app="MyApp" ng-controller="MyController">
    <table id="tblOrders" class="table table-responsive">
        <tr>
            <th>Cname</th>
            <th>Ctype</th>
            <th>From Table</th>
            <th>DisplayCName</th>
            <th>ValueCName</th>
            <th>Date</th>
        </tr>
        <tbody ng-repeat="detail in Details">
            <tr>
                <td>{{detail.CName}}</td>
                <td>
                    <select ng-model="detail.CType" class="form-control" ng-change="TypeChange(detail.CType,detail.CName)">
                        <option value="audi" selected>Select value</option>
                        <option value="Dropdown">Dropdown</option>
                        <option value="Textbox">Textbox</option>
                        <option value="DatePicker">DatePicker</option>
                    </select>
                </td>
                <td><input type="text" class="form-control" ng-model="detail.FromTable" ng-disabled="detail.isDisabledFromTable" /></td>
                <td><input type="text" class="form-control" ng-model="detail.DisplayCName" ng-disabled="detail.isDisabledDisplayCName" /></td>
                <td><input type="text" class="form-control" ng-model="detail.ValueCName" ng-disabled="detail.isDisabledValueCName" /></td>
                <td>
                    <select ng-model="detail.Date" class="form-control" ng-disabled="detail.isDisabledDate">
                        <option value="Today">Today</option>
                        <option value="Lastday">Lastday</option>
                    </select>
                </td>
            </tr>
        </tbody>
    </table>
</div>

Demo