I am updating a form to have two sets of radio buttons that turns on or off panels. The first says "Yes" to contact the customer or "No". If we are to contact, then present choice of which method is used, phone or email. (Previously there was just the question to contact or not.)
While I can get the show function to work properly, I do not understand why I cannot get the radio button to show as selected. (It could be that I am fairly green to AngularJS.)
<div class="radio styled-radio" id="callTheCustomerDiv">
<input class="form-control" id="callTheCustomerRadio1"
name="callTheCustomer" type="radio" value="Yes"
ng-required="issueType=='IncidentDiv'"
ng-model="$parent.callTheCustomer"
ng-click="contactSelection('none')"/>
<label for="callTheCustomerRadio1"> Yes</label> - Please indicate how the customer wants to be contacted.<br/>
<div class="form-group" id="howToContactDiv" ng-show=state class="row fullWidth">
<div id="contactOptions" class="form-group">
<label for="phoneRadio">Phone</label>
<!-- radio indicator is not working correctly -->
<input id="phoneRadio" class="form-control" type="radio"
ng-click="contactSelection('phone')"
name="phoneSelect" ng-model="$parent.phoneSelect"
value="{{$parent.phoneSelect}}" />
<label for="emailRadio">Email</label>
<input id="emailRadio" class="form-control" type="radio"
ng-click="contactSelection('email')" name="emailSelect"
ng-model="$parent.emailSelect"
value="{{$parent.emailSelect}}" />
<br/> <!-- phoneSelect : {{phoneSelect}} -->
</div>
<div id="phoneContact" ng-show="contactType=='phone'">
<span>Phone
<input class="form-control input-sm" type="text"
name="callTheCustomerPhone"
id="callTheCustomerPhone"
ng-model="$parent.callTheCustomerPhone"
ng-required="$parent.contactType=='phone' && accForm.phoneNumber.$viewValue === ''"
maxlength="20"/>
</span>
</div>
<br/>
<div id="emailContact" ng-show="contactType=='email'">
<span>Email
<input class="form-control input-sm" type="text"
name="emailTheCustomer" id="emailTheCustomer"
ng-model="$parent.emailTheCustomer"
ng-required="$parent.contactType=='email' && accForm.emailTheCustomer.$viewValue === ''"
maxlength="150"/></span>
</div>
</div>
<input class="form-control" id="callTheCustomerRadio2"
name="callTheCustomer" type="radio" value="No"
ng-required="issueType=='IncidentDiv'"
ng-model="$parent.callTheCustomer"
ng-click="contactSelection('no')"/>
<label for="callTheCustomerRadio2">No</label>
</div>
Looks like this when Phone is selected:
and like this when email is selected:
I added this method to the Main controller:
$scope.contactSelection = (function (contact) {
if (contact=='none'
||contact=='email'
||contact=='phone'){
$scope.state = true;
$scope.contactType = contact;
if (contact=='phone'){$scope.phoneSelect = true;$scope.emailSelect = false;}
if (contact=='email'){$scope.emailSelect = true;$scope.phoneSelect = false;}
}else{
$scope.state = false;
$scope.contactType = 'no';
$scope.emailTheCustomer = '';
$scope.callTheCustomerPhone = '';
$scope.phoneSelect = false;
$scope.emailSelect = false;
}
});