forked from aurelia/validation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70b1176
commit b664812
Showing
82 changed files
with
1,742 additions
and
839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { TaskQueue } from 'aurelia-task-queue'; | ||
import { ValidationController } from './validation-controller'; | ||
/** | ||
* Binding behavior. Indicates the bound property should be validated. | ||
*/ | ||
export declare abstract class ValidateBindingBehaviorBase { | ||
private taskQueue; | ||
constructor(taskQueue: TaskQueue); | ||
protected abstract getValidateTrigger(controller: ValidationController): number; | ||
/** | ||
* Gets the DOM element associated with the data-binding. Most of the time it's | ||
* the binding.target but sometimes binding.target is an aurelia custom element, | ||
* or custom attribute which is a javascript "class" instance, so we need to use | ||
* the controller's container to retrieve the actual DOM element. | ||
*/ | ||
getTarget(binding: any, view: any): any; | ||
bind(binding: any, source: any, rulesOrController?: ValidationController | any, rules?: any): void; | ||
unbind(binding: any): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
define(["require", "exports", 'aurelia-dependency-injection', 'aurelia-pal', './validation-controller', './validate-trigger'], function (require, exports, aurelia_dependency_injection_1, aurelia_pal_1, validation_controller_1, validate_trigger_1) { | ||
"use strict"; | ||
/** | ||
* Binding behavior. Indicates the bound property should be validated. | ||
*/ | ||
var ValidateBindingBehaviorBase = (function () { | ||
function ValidateBindingBehaviorBase(taskQueue) { | ||
this.taskQueue = taskQueue; | ||
} | ||
/** | ||
* Gets the DOM element associated with the data-binding. Most of the time it's | ||
* the binding.target but sometimes binding.target is an aurelia custom element, | ||
* or custom attribute which is a javascript "class" instance, so we need to use | ||
* the controller's container to retrieve the actual DOM element. | ||
*/ | ||
ValidateBindingBehaviorBase.prototype.getTarget = function (binding, view) { | ||
var target = binding.target; | ||
// DOM element | ||
if (target instanceof Element) { | ||
return target; | ||
} | ||
// custom element or custom attribute | ||
for (var i = 0, ii = view.controllers.length; i < ii; i++) { | ||
var controller = view.controllers[i]; | ||
if (controller.viewModel === target) { | ||
var element = controller.container.get(aurelia_pal_1.DOM.Element); | ||
if (element) { | ||
return element; | ||
} | ||
throw new Error("Unable to locate target element for \"" + binding.sourceExpression + "\"."); | ||
} | ||
} | ||
throw new Error("Unable to locate target element for \"" + binding.sourceExpression + "\"."); | ||
}; | ||
ValidateBindingBehaviorBase.prototype.bind = function (binding, source, rulesOrController, rules) { | ||
var _this = this; | ||
// identify the target element. | ||
var target = this.getTarget(binding, source); | ||
// locate the controller. | ||
var controller; | ||
if (rulesOrController instanceof validation_controller_1.ValidationController) { | ||
controller = rulesOrController; | ||
} | ||
else { | ||
controller = source.container.get(aurelia_dependency_injection_1.Optional.of(validation_controller_1.ValidationController)); | ||
rules = rulesOrController; | ||
} | ||
if (controller === null) { | ||
throw new Error("A ValidationController has not been registered."); | ||
} | ||
controller.registerBinding(binding, target, rules); | ||
binding.validationController = controller; | ||
var trigger = this.getValidateTrigger(controller); | ||
if (trigger & validate_trigger_1.validateTrigger.change) { | ||
binding.standardUpdateSource = binding.updateSource; | ||
binding.updateSource = function (value) { | ||
this.standardUpdateSource(value); | ||
this.validationController.validateBinding(this); | ||
}; | ||
} | ||
if (trigger & validate_trigger_1.validateTrigger.blur) { | ||
binding.validateBlurHandler = function () { | ||
_this.taskQueue.queueMicroTask(function () { return controller.validateBinding(binding); }); | ||
}; | ||
binding.validateTarget = target; | ||
target.addEventListener('blur', binding.validateBlurHandler); | ||
} | ||
if (trigger !== validate_trigger_1.validateTrigger.manual) { | ||
binding.standardUpdateTarget = binding.updateTarget; | ||
binding.updateTarget = function (value) { | ||
this.standardUpdateTarget(value); | ||
this.validationController.resetBinding(this); | ||
}; | ||
} | ||
}; | ||
ValidateBindingBehaviorBase.prototype.unbind = function (binding) { | ||
// reset the binding to it's original state. | ||
if (binding.standardUpdateSource) { | ||
binding.updateSource = binding.standardUpdateSource; | ||
binding.standardUpdateSource = null; | ||
} | ||
if (binding.standardUpdateTarget) { | ||
binding.updateTarget = binding.standardUpdateTarget; | ||
binding.standardUpdateTarget = null; | ||
} | ||
if (binding.validateBlurHandler) { | ||
binding.validateTarget.removeEventListener('blur', binding.validateBlurHandler); | ||
binding.validateBlurHandler = null; | ||
binding.validateTarget = null; | ||
} | ||
binding.validationController.unregisterBinding(binding); | ||
binding.validationController = null; | ||
}; | ||
return ValidateBindingBehaviorBase; | ||
}()); | ||
exports.ValidateBindingBehaviorBase = ValidateBindingBehaviorBase; | ||
}); |
Oops, something went wrong.