I am working on a registration form page that includes a person_id field and a drop down list called condition_code_1. The person_id field is mandatory, while the condition_code_1 drop down list is optional for the user to select. The values for the drop down list are retrieved from a specialConds array which is sourced from an Oracle database field.
In my Condition_code_1 controller, I store the selected value of the drop down list in a data array. However, when the user submits the form without selecting anything from the list, AngularJS throws an error: Cannot read property 'condCode1' of null. How can I handle this situation and ignore the drop down list when it is not selected?
1) Condition_code_1 list
<select id = "condition_code_1"
data-placeholder = "Please select"
ng-model = "specialCond.condCode1"
ng-options = "t.condCode as t.condDesc for t in specialConds" chosen>
<option value=""> </option>
</select>
2) Condition_code_1 Controller
$scope.create = function () {
var data = {};
data.personId = $scope.person_id;
data.conditionCode1 = $scope.specialCond.condCode1;
CondCodeSvc.create(data, function(res){
jAlert('Create successful');
}, errSvc.errorHandler);
};