Skip to content

Instantly share code, notes, and snippets.

@grofit
Created August 4, 2016 20:34
Show Gist options
  • Save grofit/27fc02a9fbf1a08aa02292f9d223a5aa to your computer and use it in GitHub Desktop.
Save grofit/27fc02a9fbf1a08aa02292f9d223a5aa to your computer and use it in GitHub Desktop.
CommonJS test for validation group failure
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ValidateProperty = undefined;
var _dec, _dec2, _class;
var _aureliaFramework = require("aurelia-framework");
var _validationStrategy = require("../strategy/validation-strategy");
var ValidateProperty = exports.ValidateProperty = (_dec = (0, _aureliaFramework.customAttribute)('validate-property'), _dec2 = (0, _aureliaFramework.inject)(Element, _validationStrategy.ValidationStrategy), _dec(_class = _dec2(_class = function () {
function ValidateProperty(element, validationStrategy) {
var _this = this;
this._validationStateHandler = function (args) {
if (args.isValid) {
_this.validationStrategy.actionValidProperty(_this.element, _this.value);
} else {
_this.validationStrategy.actionInvalidProperty(_this.element, _this.value, args.error);
}
};
this._validationPredicate = function (x) {
return x.property == _this.value;
};
this.setupValidation = function () {
_this._activeSubscription = _this.validationGroup.propertyStateChangedEvent.subscribe(_this._validationStateHandler, _this._validationPredicate);
};
this.element = element;
this.validationStrategy = validationStrategy;
}
ValidateProperty.prototype._isWithinChildBinding = function _isWithinChildBinding(overrideContext) {
return overrideContext["$index"] || overrideContext["$even"] || overrideContext["$odd"];
};
ValidateProperty.prototype.bind = function bind(binding, overrideContext) {
this.bindingContext = overrideContext;
};
ValidateProperty.prototype.attached = function attached() {
var _this2 = this;
if (this._isWithinChildBinding(this.bindingContext)) {
this.bindingContext = this.bindingContext.parentOverrideContext;
}
this.validationGroup = this.bindingContext.validationGroup;
this.validationOptions = this.bindingContext.validationOptions || {};
if (this.validationGroup) {
this.setupValidation();
this.validationGroup.getPropertyError(this.value).then(function (error) {
if (error) {
_this2.validationStrategy.actionInvalidProperty(_this2.element, _this2.value, error);
}
});
}
};
ValidateProperty.prototype.detached = function detached() {
if (this._activeSubscription) {
this._activeSubscription();
}
};
return ValidateProperty;
}()) || _class) || _class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment