Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Change names for validation summary to make breaking changes more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekrey committed Jun 12, 2015
1 parent eab6c69 commit fd2439a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
link = (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes, ctrl: ng.IFormController): void => {
element.on('click', ($event) => {
// Cancels the suppression of validation messages, which reveals error classes, validation summaries, etc.
this.validation.showValidationSummary(scope, true);
this.validation.cancelSuppress(scope);
this.validation.validationSummaryVisible(scope, true);
scope.$digest();
if (ctrl.$invalid) {
$event.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
scope.started = false;
scope.validationSummary = [];
var parentScope = scope.$parent;
var update = () => {
if (!this.validation.showValidationSummary(parentScope)) return;
var update = () => {
if (!this.validation.validationSummaryVisible(parentScope)) return;
var rawHtml: string[] = [];
var merged: any[] = [];
// flatten the nested arrays into "merged"
Expand Down Expand Up @@ -55,7 +55,7 @@
// Here we don't need to dispose our watch because we have an isolated scope that goes away when the element does.
var watches = [
parentScope.$watchCollection(this.validation.messageArray, update),
parentScope.$watch(() => this.validation.showValidationSummary(parentScope), update)
parentScope.$watch(() => this.validation.validationSummaryVisible(parentScope), update)
];

element.on('$destroy',() => angular.forEach(watches, (watch) => watch()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module ResponsivePath.Validation.Unobtrusive {
var cancelSuppressionEvent = 'unobtrusiveValidation-supression-cancel';
var showValidationSummaryEvent = 'unobtrusiveValidation-summary-show';
var hideValidationSummaryEvent = 'unobtrusiveValidation-summary-hide';

export interface GetSetMessageArray {
(scope: ng.IScope): ITrustedHtmlSet;
Expand All @@ -18,10 +20,16 @@
private getValidationType: (s: string) => ValidationType;

ensureValidation(scope: ng.IScope): ScopeValidationState {
var state: ScopeValidationState = scope['$$ validation'] || { cancelSuppress: false, messages: {}, data: {} };
var state: ScopeValidationState = scope['$$ validation'] || { cancelSuppress: false, messages: {}, data: {}, showValidationSummary: false };
scope.$on(cancelSuppressionEvent,(event) => {
state.cancelSuppress = true;
});
scope.$on(showValidationSummaryEvent,(event) => {
state.showValidationSummary = true;
});
scope.$on(hideValidationSummaryEvent,(event) => {
state.showValidationSummary = false;
});
scope['$$ validation'] = state;
return state;
}
Expand Down Expand Up @@ -59,19 +67,21 @@
delete this.ensureValidation(scope).data[dotNetName];
}

showValidationSummary(scope: ng.IScope): boolean;
showValidationSummary(scope: ng.IScope, value: boolean): void;
validationSummaryVisible(scope: ng.IScope): boolean;
validationSummaryVisible(scope: ng.IScope, value: boolean): void;

showValidationSummary(scope: ng.IScope, value?: boolean): boolean {
validationSummaryVisible(scope: ng.IScope, value?: boolean): boolean {
if (value === undefined)
return this.ensureValidation(scope).showValidationSummary;
else {
this.ensureValidation(scope).showValidationSummary = value;
return;
if (value)
scope.$broadcast(showValidationSummaryEvent);
else
scope.$broadcast(hideValidationSummaryEvent);
}
}


static $inject = ['$injector','$sce','getValidationType'];
constructor($injector: ng.auto.IInjectorService, $sce: IMySCEService, getValidationType: (keyName: string) => ValidationType) {
this.$injector = $injector;
Expand Down
23 changes: 17 additions & 6 deletions js/angular.unobtrusive.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ var ResponsivePath;
this.require = '^?form';
this.link = function (scope, element, attrs, ctrl) {
element.on('click', function ($event) {
_this.validation.showValidationSummary(scope, true);
_this.validation.cancelSuppress(scope);
_this.validation.validationSummaryVisible(scope, true);
scope.$digest();
if (ctrl.$invalid) {
$event.preventDefault();
Expand Down Expand Up @@ -348,7 +348,7 @@ var ResponsivePath;
scope.validationSummary = [];
var parentScope = scope.$parent;
var update = function () {
if (!_this.validation.showValidationSummary(parentScope))
if (!_this.validation.validationSummaryVisible(parentScope))
return;
var rawHtml = [];
var merged = [];
Expand Down Expand Up @@ -379,7 +379,7 @@ var ResponsivePath;
};
var watches = [
parentScope.$watchCollection(_this.validation.messageArray, update),
parentScope.$watch(function () { return _this.validation.showValidationSummary(parentScope); }, update)
parentScope.$watch(function () { return _this.validation.validationSummaryVisible(parentScope); }, update)
];
element.on('$destroy', function () { return angular.forEach(watches, function (watch) { return watch(); }); });
};
Expand Down Expand Up @@ -507,6 +507,8 @@ var ResponsivePath;
var Unobtrusive;
(function (Unobtrusive) {
var cancelSuppressionEvent = 'unobtrusiveValidation-supression-cancel';
var showValidationSummaryEvent = 'unobtrusiveValidation-summary-show';
var hideValidationSummaryEvent = 'unobtrusiveValidation-summary-hide';
var ValidationService = (function () {
function ValidationService($injector, $sce, getValidationType) {
var _this = this;
Expand Down Expand Up @@ -535,10 +537,16 @@ var ResponsivePath;
this.getValidationType = getValidationType;
}
ValidationService.prototype.ensureValidation = function (scope) {
var state = scope['$$ validation'] || { cancelSuppress: false, messages: {}, data: {} };
var state = scope['$$ validation'] || { cancelSuppress: false, messages: {}, data: {}, showValidationSummary: false };
scope.$on(cancelSuppressionEvent, function (event) {
state.cancelSuppress = true;
});
scope.$on(showValidationSummaryEvent, function (event) {
state.showValidationSummary = true;
});
scope.$on(hideValidationSummaryEvent, function (event) {
state.showValidationSummary = false;
});
scope['$$ validation'] = state;
return state;
};
Expand All @@ -554,12 +562,15 @@ var ResponsivePath;
delete this.ensureValidation(scope).messages[dotNetName];
delete this.ensureValidation(scope).data[dotNetName];
};
ValidationService.prototype.showValidationSummary = function (scope, value) {
ValidationService.prototype.validationSummaryVisible = function (scope, value) {
if (value === undefined)
return this.ensureValidation(scope).showValidationSummary;
else {
this.ensureValidation(scope).showValidationSummary = value;
return;
if (value)
scope.$broadcast(showValidationSummaryEvent);
else
scope.$broadcast(hideValidationSummaryEvent);
}
};
ValidationService.$inject = ['$injector', '$sce', 'getValidationType'];
Expand Down
Loading

0 comments on commit fd2439a

Please sign in to comment.