How to enable disable a select drop down list using radio buttons with angularjs?

Ashane Alvis

I have been searching all over for the internet looking on how to enable or disable this drop down list using radio buttons specifically when the radio button value is equal to prof the drop down list should be disabled, but with no help. I did come up with an example but didn't work. Any help would be appreciated.

registration.html

<div class="form-group">
    <label class="col-lg-2 col-md-3 control-label">Qualification</label>
        <div class="col-lg-10 col-md-9">
            <div class="radio-custom radio-inline">
                <input type="radio" ng-model="QualificationDetails.qualification_type" value="edu" name="radio1" id="radio4">
                    <label for="radio4">Educational</label>
            </div>
            <div class="radio-custom radio-inline">
                <input type="radio" ng-model="QualificationDetails.qualification_type" value="prof" name="radio1" id="radio5">
                    <label for="radio5">professional</label>
            </div>
        </div>
</div>

//This is the drop down that I need to diable

<div class="form-group">
    <label class="col-sm-2 control-label" for="Qulitype">Qualification type</label>
        <div class="col-sm-10">

            <select name="repeatSelect" id="repeatSelect" ng-disabled="QualificationDetails.qualification_type == 'prof'" ng-model="QualificationDetails.qualification" class="form-control">
                <option ng-repeat="quali in qualiLevel" value="{{quali.qualification_id}}">{{quali.quali_level}}</option>
            </select>
        </div>
</div>

This is the code I implemented to work above scenario. But didn't work :(

regController.js

$scope.$watch('QualificationDetails.qualicication_type', function (QualiType) {
            if (angular.isUndefined($scope.QualificationDetails)) {
                return;
            }
            if (QualiType === 'prof') {
                $scope.QualificationDetails.qualification_type = $scope.QualiType;
            }
            else {
                if ($scope.QualificationDetails.qualification_type !== null) {
                    $scope.QualiType = $scope.QualificationDetails.qualification_type;
                    $scope.QualificationDetails.qualification_type = null;
                }
            }
        });

the above scenario is that when it comes to qualifications if qualification type is equal to professional (prof) drop down list is disabled and when it is educational the drop down list should be enabled. Any idea on how to achieve this.

This is the Quality level json. I get it through the qualitylevel.service.

(function initController() {

    deptService.getdepts(function (res) {
        $scope.depts = JSON.parse(res.data);

    });

    qualiService.getquali(function (res) {
        console.log("inside ");
        $scope.qualiLevel = JSON.parse(res.data);
    });

    console.log("inside service");

})();
Sergey Goliney

It seems to me, that your code works fine without watcher you have added. I hope I understood what you want correctly. Try this snippet:

angular
    .module('app', [])
    .controller('Ctrl', function($scope) {
        $scope.qualiLevel = [
          {quali_level: 'A', qualification_id: 1},
          {quali_level: 'B', qualification_id: 2}
        ];
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

<div ng-app="app">
<div ng-controller="Ctrl">
  
<div class="form-group">
    <label class="col-lg-2 col-md-3 control-label">Qualification</label>
        <div class="col-lg-10 col-md-9">
            <div class="radio-custom radio-inline">
                <input type="radio" ng-model="QualificationDetails.qualification_type" value="edu" name="radio1" id="radio4">
                    <label for="radio4">Educational</label>
            </div>
            <div class="radio-custom radio-inline">
                <input type="radio" ng-model="QualificationDetails.qualification_type" value="prof" name="radio1" id="radio5">
                    <label for="radio5">professional</label>
            </div>
        </div>
</div>

<div class="form-group">
    <label class="col-sm-2 control-label" for="Qulitype">Qualification type</label>
        <div class="col-sm-10">

            <select name="repeatSelect" id="repeatSelect" ng-disabled="QualificationDetails.qualification_type == 'prof'" ng-model="QualificationDetails.qualification" class="form-control">
                <option ng-repeat="quali in qualiLevel" value="{{quali.qualification_id}}">{{quali.quali_level}}</option>
            </select>
        </div>
</div>
</div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to enable / disable drop down list of Spinner

From Dev

enable/disable radio buttons in AngularJS

From Dev

How to enable and disable drop down list by selecting radio button in ASP.NET

From Dev

Any way to change a list of radio buttons to a select drop down dynamically?

From Dev

Enable / Disable kendo ui drop down list using AngularJS ng-disabled

From Dev

Javascript to disable or enable radio buttons

From Dev

Javascript to disable or enable radio buttons

From Dev

datepicker : disable days using drop down list?

From Dev

datepicker : disable days using drop down list?

From Dev

How to disable certain options in a drop down select?

From Dev

How to fill drop down list values using AngularJS

From Dev

How To Filter A Grid In AngularJS Using A Drop Down List

From Dev

How to select one drop down list using capybara

From Dev

How to disable drop down list in JSP?

From Dev

How to pre-select radio buttons in angularjs

From Dev

How to Enable and Disable Buttons

From Dev

How to disable a drop down list item in dropdown list on load using jquery

From Dev

how to select specific drop down list Item

From Dev

how to select specific drop down list Item

From Dev

Enable and disable text with radio buttons with javascript?

From Java

How to select option in drop down using Capybara

From Dev

Unable to disable drop down list when using bootstrap

From Dev

How to disable first option in Drop down select menu?

From Dev

Disable and enable buttons using variables

From Dev

angularjs select drop down validation

From Dev

angularjs select drop down validation

From Dev

How to enable /disable buttons in jquery?

From Dev

Disable or enable text input forms when radio buttons are clicked, using Jquery

From Dev

How to enable/disable Bootstrap buttons remotely using jquery?

Related Related

  1. 1

    How to enable / disable drop down list of Spinner

  2. 2

    enable/disable radio buttons in AngularJS

  3. 3

    How to enable and disable drop down list by selecting radio button in ASP.NET

  4. 4

    Any way to change a list of radio buttons to a select drop down dynamically?

  5. 5

    Enable / Disable kendo ui drop down list using AngularJS ng-disabled

  6. 6

    Javascript to disable or enable radio buttons

  7. 7

    Javascript to disable or enable radio buttons

  8. 8

    datepicker : disable days using drop down list?

  9. 9

    datepicker : disable days using drop down list?

  10. 10

    How to disable certain options in a drop down select?

  11. 11

    How to fill drop down list values using AngularJS

  12. 12

    How To Filter A Grid In AngularJS Using A Drop Down List

  13. 13

    How to select one drop down list using capybara

  14. 14

    How to disable drop down list in JSP?

  15. 15

    How to pre-select radio buttons in angularjs

  16. 16

    How to Enable and Disable Buttons

  17. 17

    How to disable a drop down list item in dropdown list on load using jquery

  18. 18

    how to select specific drop down list Item

  19. 19

    how to select specific drop down list Item

  20. 20

    Enable and disable text with radio buttons with javascript?

  21. 21

    How to select option in drop down using Capybara

  22. 22

    Unable to disable drop down list when using bootstrap

  23. 23

    How to disable first option in Drop down select menu?

  24. 24

    Disable and enable buttons using variables

  25. 25

    angularjs select drop down validation

  26. 26

    angularjs select drop down validation

  27. 27

    How to enable /disable buttons in jquery?

  28. 28

    Disable or enable text input forms when radio buttons are clicked, using Jquery

  29. 29

    How to enable/disable Bootstrap buttons remotely using jquery?

HotTag

Archive