Skip to content

Commit

Permalink
Keep working on those UI behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanderhaegen committed Mar 25, 2015
1 parent 05d6195 commit 10a269a
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 436 deletions.
13 changes: 6 additions & 7 deletions dist/commonjs/validation/pathObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ var PathObserver = exports.PathObserver = (function () {
value: function getObserver() {
if (this.path.length == 1) {
return this.observerLocator.getObserver(this.subject, this.path[0]);
}
return this;
}return this;
}
},
getValue: {
Expand All @@ -112,10 +111,10 @@ var PathObserver = exports.PathObserver = (function () {
}
}
if (currentObserver.obj !== expectedSubject)
//Happens if you set a value somewhere along the binding path and immediately call getValue (on the very last observer)
{
this.observeParts(this.path[i - 1]);
break;
//Happens if you set a value somewhere along the binding path and immediately call getValue (on the very last observer)
{
this.observeParts(this.path[i - 1]);
break;
}
expectedSubject = currentObserver.getValue();
}
Expand All @@ -139,4 +138,4 @@ var PathObserver = exports.PathObserver = (function () {
});

return PathObserver;
})();
})();
77 changes: 42 additions & 35 deletions dist/commonjs/validation/validateAttachedBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ var ValidateAttachedBehavior = exports.ValidateAttachedBehavior = (function () {
_createClass(ValidateAttachedBehavior, {
valueChanged: {
value: function valueChanged(newValue) {
}
},
attached: {
value: function attached() {
if (this.value === null || this.value === undefined) throw "Cannot bind ValidateAttachedBehavior to null/undefined";
if (typeof this.value === "string") {
return; //this is just to tell the real validation instance (higher in the DOM) the exact property to bind to
if (this.value === null || this.value === undefined) {
return;
}if (typeof this.value === "string") {
return; //this is just to tell the real validation instance (higher in the DOM) the exact property-path to bind to
} else if (this.value.constructor.name === "ValidationResultProperty") {
//Binding to a single validation property
this.subscribeChangedHandlersForProperty(this.value, this.element);
Expand Down Expand Up @@ -66,7 +63,7 @@ var ValidateAttachedBehavior = exports.ValidateAttachedBehavior = (function () {
if (currentDepth === 5) {
return;
}
if (currentElement.nodeName === "LABEL" && currentElement.attributes["for"] && currentElement.attributes["for"].value === inputId) {
if (currentElement.nodeName === "LABEL" && (currentElement.attributes["for"] && currentElement.attributes["for"].value === inputId || !currentElement.attributes["for"])) {
currentLabels.push(currentElement);
}

Expand Down Expand Up @@ -123,43 +120,55 @@ var ValidateAttachedBehavior = exports.ValidateAttachedBehavior = (function () {
element.parentNode.appendChild(helpBlock);
}
}

helpBlock.textContent = validationProperty.message;
if (validationProperty) helpBlock.textContent = validationProperty.message;else helpBlock.textContent = "";
}
},
appendUIVisuals: {
value: function appendUIVisuals(validationProperty, currentElement) {
var formGroup = this.searchFormGroup(currentElement, 0);
if (formGroup) {
if (validationProperty) {
if (validationProperty.isValid) {
formGroup.classList.remove("has-warning");
formGroup.classList.add("has-success");
} else {
formGroup.classList.remove("has-success");
formGroup.classList.add("has-warning");
}
} else {
formGroup.classList.remove("has-warning");
formGroup.classList.remove("has-success");
}
if (this.config.appendMessageToInput) {
this.appendMessageToElement(currentElement, validationProperty);
}
if (this.config.appendMessageToLabel) {
var labels = this.findLabels(formGroup, currentElement.id);
for (var ii = 0; ii < labels.length; ii++) {
var label = labels[ii];
this.appendMessageToElement(label, validationProperty);
}
}
}
}
},
subscribeChangedHandlersForProperty: {
value: function subscribeChangedHandlersForProperty(validationProperty, currentElement) {
var _this = this;

if (validationProperty !== undefined) {
this.appendUIVisuals(null, currentElement);
validationProperty.onValidate(function (validationProperty) {
var formGroup = _this.searchFormGroup(currentElement, 0);
if (formGroup) {
if (validationProperty.isValid) {
formGroup.classList.remove("has-warning");
formGroup.classList.add("has-success");
} else {
formGroup.classList.remove("has-success");
formGroup.classList.add("has-warning");
}
if (_this.config.appendMessageToInput) {
_this.appendMessageToElement(currentElement, validationProperty);
}
if (_this.config.appendMessageToLabel) {
var labels = _this.findLabels(formGroup, currentElement.id);
for (var ii = 0; ii < labels.length; ii++) {
var label = labels[ii];
_this.appendMessageToElement(label, validationProperty);
}
}
}
_this.appendUIVisuals(validationProperty, currentElement);
});
}
}
},
detached: {
value: function detached() {
}
value: function detached() {}
},
attached: {
value: function attached() {}
}
}, {
metadata: {
Expand All @@ -175,6 +184,4 @@ var ValidateAttachedBehavior = exports.ValidateAttachedBehavior = (function () {
});

return ValidateAttachedBehavior;
})();

//This empty method must be here, aurelia will not set this.value if it's not :-O
})();
12 changes: 3 additions & 9 deletions dist/commonjs/validation/validationRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ var BetweenLengthValidationRule = exports.BetweenLengthValidationRule = (functio
function BetweenLengthValidationRule(minimumLength, maximumLength) {
_classCallCheck(this, BetweenLengthValidationRule);

_get(Object.getPrototypeOf(BetweenLengthValidationRule.prototype), "constructor", this).call(this, {
minimumLength: minimumLength,
maximumLength: maximumLength
}, function (newValue, threshold) {
_get(Object.getPrototypeOf(BetweenLengthValidationRule.prototype), "constructor", this).call(this, { minimumLength: minimumLength, maximumLength: maximumLength }, function (newValue, threshold) {
return newValue.length !== undefined && newValue.length >= threshold.minimumLength && newValue.length < threshold.maximumLength;
});
}
Expand Down Expand Up @@ -203,10 +200,7 @@ var BetweenValueValidationRule = exports.BetweenValueValidationRule = (function
function BetweenValueValidationRule(minimumValue, maximumValue) {
_classCallCheck(this, BetweenValueValidationRule);

_get(Object.getPrototypeOf(BetweenValueValidationRule.prototype), "constructor", this).call(this, {
minimumValue: minimumValue,
maximumValue: maximumValue
}, function (newValue, threshold) {
_get(Object.getPrototypeOf(BetweenValueValidationRule.prototype), "constructor", this).call(this, { minimumValue: minimumValue, maximumValue: maximumValue }, function (newValue, threshold) {
return threshold.minimumValue <= newValue && newValue < threshold.maximumValue;
});
}
Expand Down Expand Up @@ -325,4 +319,4 @@ var InCollectionValidationRule = exports.InCollectionValidationRule = (function
_inherits(InCollectionValidationRule, _ValidationRule16);

return InCollectionValidationRule;
})(ValidationRule);
})(ValidationRule);
9 changes: 4 additions & 5 deletions dist/commonjs/validation/validationRulesCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var SwitchCaseValidationRulesCollection = exports.SwitchCaseValidationRulesColle
this.innerCollections = [];
this.defaultCollection = new ValidationRulesCollection();
this.caseLabel = "";
this.defaultCaseLabel = {description: "this is the case label for 'default'"};
this.defaultCaseLabel = { description: "this is the case label for 'default'" };
}

_createClass(SwitchCaseValidationRulesCollection, {
Expand All @@ -110,8 +110,7 @@ var SwitchCaseValidationRulesCollection = exports.SwitchCaseValidationRulesColle

if (caseLabel === this.defaultCaseLabel) {
return this.defaultCollection;
}
var currentCollection = null;
}var currentCollection = null;
for (var i = 0; i < this.innerCollections.length; i++) {
currentCollection = this.innerCollections[i];
if (currentCollection.caseLabel === caseLabel) {
Expand Down Expand Up @@ -154,10 +153,10 @@ var SwitchCaseValidationRulesCollection = exports.SwitchCaseValidationRulesColle
notEmpty: {
value: function notEmpty() {
var collection = this.getCurrentCollection(this.caseLabel);
if (collection !== null) collection.notEmpty(); else this.defaultCollection.notEmpty();
if (collection !== null) collection.notEmpty();else this.defaultCollection.notEmpty();
}
}
});

return SwitchCaseValidationRulesCollection;
})();
})();
78 changes: 47 additions & 31 deletions dist/es6/validation/validateAttachedBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ export class ValidateAttachedBehavior {
}

valueChanged(newValue) {
//This empty method must be here, aurelia will not set this.value if it's not :-O
}

attached() {
if (this.value === null || this.value === undefined)
throw 'Cannot bind ValidateAttachedBehavior to null/undefined';
return;
if (typeof (this.value) === 'string') {
return; //this is just to tell the real validation instance (higher in the DOM) the exact property to bind to
return; //this is just to tell the real validation instance (higher in the DOM) the exact property-path to bind to
}
else if (this.value.constructor.name === 'ValidationResultProperty') {
//Binding to a single validation property
Expand All @@ -39,6 +35,7 @@ export class ValidateAttachedBehavior {
}
}


searchFormGroup(currentElement, currentDepth) {
if (currentDepth === 5) {
return null;
Expand All @@ -61,8 +58,10 @@ export class ValidateAttachedBehavior {
return;
}
if (currentElement.nodeName === "LABEL" &&
currentElement.attributes['for'] &&
currentElement.attributes['for'].value === inputId) {
((currentElement.attributes['for'] && currentElement.attributes['for'].value === inputId) ||
(!currentElement.attributes['for']))
)
{
currentLabels.push(currentElement);
}

Expand Down Expand Up @@ -119,41 +118,58 @@ export class ValidateAttachedBehavior {
element.parentNode.appendChild(helpBlock);
}
}
if(validationProperty)
helpBlock.textContent = validationProperty.message;
else
helpBlock.textContent = '';
}

appendUIVisuals(validationProperty, currentElement)
{
var formGroup = this.searchFormGroup(currentElement, 0);
if (formGroup) {
if(validationProperty) {
if (validationProperty.isValid) {
formGroup.classList.remove('has-warning');
formGroup.classList.add('has-success');
}
else {
formGroup.classList.remove('has-success');
formGroup.classList.add('has-warning');
}
}
else{
formGroup.classList.remove('has-warning');
formGroup.classList.remove('has-success');
}
if (this.config.appendMessageToInput) {
this.appendMessageToElement(currentElement, validationProperty);
}
if (this.config.appendMessageToLabel) {
var labels = this.findLabels(formGroup, currentElement.id);
for (var ii = 0; ii < labels.length; ii++) {
var label = labels[ii];
this.appendMessageToElement(label, validationProperty);

helpBlock.textContent = validationProperty.message;
}
}
}
}

subscribeChangedHandlersForProperty(validationProperty, currentElement) {
if (validationProperty !== undefined) {
this.appendUIVisuals(null, currentElement);
validationProperty.onValidate(
(validationProperty) => {
var formGroup = this.searchFormGroup(currentElement, 0);
if (formGroup) {
if (validationProperty.isValid) {
formGroup.classList.remove('has-warning');
formGroup.classList.add('has-success');
}
else {
formGroup.classList.remove('has-success');
formGroup.classList.add('has-warning');
}
if (this.config.appendMessageToInput) {
this.appendMessageToElement(currentElement, validationProperty);
}
if (this.config.appendMessageToLabel) {
var labels = this.findLabels(formGroup, currentElement.id);
for (var ii = 0; ii < labels.length; ii++) {
var label = labels[ii];
this.appendMessageToElement(label, validationProperty);

}
}
}
this.appendUIVisuals(validationProperty, currentElement);
}
);
}
}

detached() {
}

attached() {
}
}
10 changes: 5 additions & 5 deletions dist/system/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ System.register(["./validation/validationLocaleRepository", "./validation/valida
}

ValidateAttachedBehavior = _validationValidateAttachedBehavior.ValidateAttachedBehavior;
}, function (_validationValidateAttachedBehaviorConfig) {
for (var _key8 in _validationValidateAttachedBehaviorConfig) {
_export(_key8, _validationValidateAttachedBehaviorConfig[_key8]);
}
}, function (_validationValidateAttachedBehaviorConfig) {
for (var _key8 in _validationValidateAttachedBehaviorConfig) {
_export(_key8, _validationValidateAttachedBehaviorConfig[_key8]);
}
}],
execute: function () {
"use strict";
}
};
});
});
Loading

0 comments on commit 10a269a

Please sign in to comment.