From: Tim Otten Date: Thu, 12 Feb 2015 00:31:53 +0000 (-0800) Subject: CRM-15856 - crmMailingRecipients - Respect ngRequired X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7bb19768439f9a034223dd612be2c81f1306c389;p=civicrm-core.git CRM-15856 - crmMailingRecipients - Respect ngRequired --- diff --git a/js/angular-crmMailing/directives.js b/js/angular-crmMailing/directives.js index d86fed8cfa..1ba5449fbe 100644 --- a/js/angular-crmMailing/directives.js +++ b/js/angular-crmMailing/directives.js @@ -233,6 +233,7 @@ scope: { crmAvailGroups: '@', // available groups crmAvailMailings: '@', // available mailings + ngRequired: '@' }, templateUrl: '~/crmMailing/directive/recipients.html', link: function (scope, element, attrs, ngModel) { @@ -289,6 +290,7 @@ scope.recips = ngModel.$viewValue; if (ngModel.$viewValue) { $(element).select2('val', convertMailingToValues(ngModel.$viewValue)); + validate(); } }; @@ -304,6 +306,15 @@ return " " + item.text + ""; } + function validate() { + if (scope.$parent.$eval(attrs.ngRequired)) { + var empty = (_.isEmpty(ngModel.$viewValue.groups.include) && _.isEmpty(ngModel.$viewValue.mailings.include)); + ngModel.$setValidity('empty', !empty); + } else { + ngModel.$setValidity('empty', true); + } + } + $(element).select2({ dropdownAutoWidth: true, placeholder: "Groups or Past Recipients", @@ -311,7 +322,7 @@ formatSelection: formatItem, escapeMarkup: function (m) { return m; - }, + } }); $(element).on('select2-selecting', function (e) { @@ -327,6 +338,7 @@ } scope.$apply(); $(element).select2('close'); + validate(); e.preventDefault(); }); @@ -336,6 +348,7 @@ scope.$parent.$apply(function () { arrayRemove(ngModel.$viewValue[typeKey][option.mode], option.entity_id); }); + validate(); e.preventDefault(); }); diff --git a/partials/crmMailing/recipients.html b/partials/crmMailing/recipients.html index 3306ef4aea..90d1918540 100644 --- a/partials/crmMailing/recipients.html +++ b/partials/crmMailing/recipients.html @@ -22,7 +22,7 @@ crm-avail-mailings="crmMailingConst.civiMails | filter:{is_completed:1}" crm-ui-id="{{crmMailingBlockRecipients.id}}" name="{{crmMailingBlockRecipients.name}}" - required + ng-required="true" multiple>