Vereonix
Vereonix

Reputation: 1413

Bootstrap 4 'data-toggle' preventing AngualrJS model updating

I've seen this mentioned as an issue for Bootstrap 3 with no official fix, but not mentioned for Bootstrap 4.

Plunker Demo of issue

The data-toggle is used on a radio input, when data-toggle is on the input the AJS model isn't updated, but without it it is. Plus the added issue of if I don't use data-toggle then no toggle affect is applied to the selected radio option.

<html ng-app="testApp">

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=11" />

    <!-- CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <!-- JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <!--ISSUE SCRIPT - data-toggle -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

    <script src="https://code.angularjs.org/1.4.0/angular.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-messages.js"></script>
    <script src="script.js"></script>
</head>

  <body ng-controller="testController">
        <form>
           <!-- YES/NO -->
                <div class="form-group required">
                  <label class="input-label">Do you have any debt?</label>
                    <div class="btn-group btn-group-toggle" data-toggle="buttons">
                      <label class="btn btn-secondary">
                        <input type="radio" name="HasDebt" autocomplete="off"
                          ng-value="true"
                          ng-model="User.HasDebt"> Yes
                      </label>
                      <label class="btn btn-secondary">
                        <input type="radio" name="HasDebt" autocomplete="off"
                          ng-value="false"
                          ng-model="User.HasDebt"> No
                      </label>
                    </div>
                </div>
                Value: {{User.HasDebt}}
        </form>
  </body>

</html>

Upvotes: 0

Views: 45

Answers (1)

TheUnKnown
TheUnKnown

Reputation: 681

The AngularJS version that you are using is not compatible with jQuery it seems. Please replace it with the latest version. Below is the index.html file:

<!DOCTYPE html>
<html ng-app="testApp">

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=11" />

    <!-- CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <!-- JS -->

    <!--ISSUE SCRIPT - data-toggle -->
            <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
         <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-messages.js"></script>
    <script src="script.js"></script>

</head>

  <body ng-controller="testController">
        <form>
           <!-- YES/NO -->
                <div class="form-group required">
                  <label class="input-label">Do you have any debt?</label>
                    <div class="btn-group btn-group-toggle" data-toggle="buttons">
                      <label class="btn btn-secondary">
                        <input type="radio" name="HasDebt" autocomplete="off"
                          ng-value="true"
                          ng-model="User.HasDebt"> Yes
                      </label>
                      <label class="btn btn-secondary">
                        <input type="radio" name="HasDebt" autocomplete="off"
                          ng-value="false"
                          ng-model="User.HasDebt"> No
                      </label>
                    </div>
                </div>
                Value: {{User.HasDebt}}
        </form>

  </body>

</html>

Hope it helps.

Upvotes: 1

Related Questions