mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
d0c151be70
closes #5336 - creates gh-form-group component to handle form group status - refactors current validation methods to work on a per-property basis - adds gh-error-message component to render error message - removes (comments out) tests that pertain to the old notifications until the new inline validation is added
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import Ember from 'ember';
|
|
|
|
/**
|
|
* Base validator that all validators should extend
|
|
* Handles checking of individual properties or the entire model
|
|
*/
|
|
var BaseValidator = Ember.Object.extend({
|
|
properties: [],
|
|
passed: false,
|
|
|
|
/**
|
|
* When passed a model and (optionally) a property name,
|
|
* checks it against a list of validation functions
|
|
* @param {Ember.Object} model Model to validate
|
|
* @param {string} prop Property name to check
|
|
* @return {boolean} True if the model passed all (or one) validation(s),
|
|
* false if not
|
|
*/
|
|
check: function (model, prop) {
|
|
var self = this;
|
|
|
|
this.set('passed', true);
|
|
|
|
if (prop && this[prop]) {
|
|
this[prop](model);
|
|
} else {
|
|
this.get('properties').forEach(function (property) {
|
|
if (self[property]) {
|
|
self[property](model);
|
|
}
|
|
});
|
|
}
|
|
return this.get('passed');
|
|
},
|
|
invalidate: function () {
|
|
this.set('passed', false);
|
|
}
|
|
});
|
|
|
|
export default BaseValidator;
|