2

based on a customer name user can check the delivery radio button but if there is no customer delivery radio button should not be checked another radio button pickup is there should be checked in that condition.

what i am doing is working fine but radio button is not coming checked .. can anyone help me on that. here is my code

  <div class="form-row-redio-btn">
      <div class="LevelDiv" style="padding: 5px 15px;">Shipment Type</div>
      <input type="radio" data-ng-value="true" id="radioOne" data-ng-model="IsPickup" name="account" checked data-ng-checked="IsPickup"/>
      <label for="radioOne" class="radio">Pick up</label>
      <input type="radio" data-ng-value="false" id="radioTwo" name="account" data-ng-model="IsPickup" data-ng-change="checkCustomer();"/>
      <label for="radioTwo" class="radio">Delivery</label>
  </div>

js

 //check if the customer is selected or not.
    $scope.checkCustomer = function () {
        if (!$scope.CustomerName) {
            toastr.clear();
            $scope.IsPickup = true;
            console.log($scope.IsPickup);
            toastr["error"]('Please select a customer as the shipment type is delivery!');
            return false;
        }
    }
Varit J Patel
  • 3,497
  • 1
  • 13
  • 21
Miranda
  • 259
  • 1
  • 8
  • 19

1 Answers1

0

model you are using same model for two radio buttons and also if customer is empty u can change the model to true which u wants to check

JS

$scope.IsPickup = true;
  $scope.checkmyname = function () {
        if (!$scope.CustomerName) {
          alert('No customer so default to Delivery')
           $scope.IsPickup = false;
            $scope.Isdelivery = true;       
            }
        else
        {
           $scope.IsPickup = true;
            $scope.Isdelivery = false;
             alert('Have customer')
        }

    }

HTML

<input type="text" ng-model="CustomerName" />
      <div class="form-row-redio-btn">
                        <div class="LevelDiv" style="padding: 5px 15px;">Shipment Type</div>
                        <input type="radio" data-ng-value="true" id="radioOne" data-ng-model="IsPickup" name="account" checked data-ng-checked="IsPickup"/>
                        <label for="radioOne" class="radio">Pick up</label>
                        <input type="radio" data-ng-value="true" id="radioTwo" name="delivery" data-ng-model="Isdelivery" data-ng-change="checkCustomer();"/>
                        <label for="radioTwo" class="radio">Delivery</label>
                    </div>
                    <button ng-click="checkmyname()"> check custmor name </button>

enter the customer name in the input and delet the customer name in the input and check for reference https://plnkr.co/edit/NAJqlM7kNeJfv5lzNUg1

Gayathri Mohan
  • 2,924
  • 4
  • 19
  • 25