mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 11:20:39 -03:30
Add validation to the multi-select questions in survey
This commit is contained in:
parent
5907b3dcad
commit
37bfa3c3a8
@ -1371,4 +1371,33 @@ function(ConfigurationUtils, i18n, $rootScope) {
|
||||
});
|
||||
}
|
||||
};
|
||||
}])
|
||||
|
||||
.directive('awRequireMultiple', [function() {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function postLink(scope, element, attrs, ngModel) {
|
||||
// Watch for changes to the required attribute
|
||||
attrs.$observe('required', function(value) {
|
||||
if(value) {
|
||||
ngModel.$validators.required = function (value) {
|
||||
if(angular.isArray(value)) {
|
||||
if(value.length === 0) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return (!value[0] || value[0] === "") ? false : true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
delete ngModel.$validators.required;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}]);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<div>
|
||||
<select class="form-control SurveyMaker-previewSelect" ng-model="selectedValue" multi-select ng-required="isRequired" ng-disabled="isDisabled">
|
||||
<select class="form-control SurveyMaker-previewSelect" ng-model="selectedValue" multi-select ng-required="isRequired" ng-disabled="isDisabled" aw-require-multiple>
|
||||
<option ng-repeat="choice in choices" value="{{choice}}">{{choice}}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user