Commit c173d79e authored by jaapjansma's avatar jaapjansma

fixed removing of validators and/or adding existing validators

parent bc44bce2
......@@ -17,7 +17,7 @@
/**
* @var array<AbstractValidator>
*/
protected $types = array();
protected $validators = array();
/**
* @var Factory
......
......@@ -147,9 +147,9 @@
input.type = type;
if (input.deletedValidators) {
angular.forEach(input.deletedValidators, function (validator, validator_index) {
if (validator.id) {
crmApi('FormProcessorValidator', 'delete', {'id': id});
angular.forEach(input.deletedValidators, function (deletedValidator, validator_index) {
if (deletedValidator.id) {
crmApi('FormProcessorValidation', 'delete', {'id': deletedValidator.id});
}
});
}
......
......@@ -67,10 +67,10 @@
ui-jq="select2"
ui-options="{dropdownAutoWidth : true, allowClear: true}"
ng-model="newValidator"
ng-options="newValidator.label for newValidator in validators">
ng-options="validator.label for validator in validators track by validator.name">
<option value="">{{ts('- Select validation -')}}</option>
</select>
<button crm-icon="fa-plus" ng-click="addValidator(newValidator)">{{ts('Add validation rule')}}</button>
<button crm-icon="fa-plus" ng-click="addValidator(newValidator);">{{ts('Add validation rule')}}</button>
</div>
</div>
</div>
......
(function(angular, $, _) {
function getValidators($scope) {
var validators = []
for(var validator_name in CRM.form_processor.validators) {
var validator = CRM.form_processor.validators[validator_name];
var exists = false;
for (var i = 0; i < $scope.input.validators.length; i++) {
if ($scope.input.validators[i].validator.name == validator.name) {
exists = true;
break;
}
}
if (!exists) {
validators.push(validator);
}
}
return validators;
}
angular.module('form_processor').controller('InputDialogCtrl', function InputDialogCtrl($scope, dialogService, crmApi) {
$scope.ts = CRM.ts(null);
$scope.input = angular.copy($scope.model.input);
$scope.locks = {name: true};
$scope.isNameValid = false;
$scope.validators = CRM.form_processor.validators;
$scope.validators = getValidators($scope);
$scope.newValidator = null;
if (!$scope.input.deletedValidators) {
$scope.input.deletedValidators = [];
}
......@@ -46,7 +65,7 @@
$scope.saveClick = function() {
for(var i=0; i<$scope.input.validators.length; i++) {
$scope.input.validators[i].configuration = {}
$scope.input.validators[i].configuration = {};
for (var key in $scope.input.validators[i].validator.configuration) {
$scope.input.validators[i].configuration[key] = $scope.input.validators[i].validator.configuration[key];
}
......@@ -63,11 +82,18 @@
if (!newValidator) {
return;
}
var validator = {
validator: angular.copy(newValidator),
configuration: angular.copy(newValidator.configuration_spec.default_configuration)
};
$scope.input.validators.push(validator);
for (var i=0; i < $scope.input.validators.length; i++) {
if ($scope.input.validators[i].validator.name == newValidator.name) {
return;
}
}
var validator = {
validator: angular.copy(newValidator),
configuration: angular.copy(newValidator.configuration_spec.default_configuration)
};
$scope.input.validators.push(validator);
$scope.validators = getValidators($scope);
return;
};
$scope.removeValidator = function(validator) {
......@@ -75,6 +101,7 @@
if (index >= 0) {
$scope.input.deletedValidators.push(validator);
$scope.input.validators.splice(index, 1);
$scope.validators = getValidators($scope);
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment