forked from massiveart/husky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
husky-validation.js
139 lines (107 loc) · 5.86 KB
/
husky-validation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* This file is part of Husky frontend development framework.
*
* (c) MASSIVE ART WebServices GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*
*/
(function() {
'use strict';
require.config({
paths: { "form": 'bower_components/husky-validation/dist/validation' }
});
define(['form'], function(Form) {
return {
name: 'husky-validation',
initialize: function(app) {
app.sandbox.form = {
create: function(selector, options) {
return new Form($(selector), options);
},
getObject: function(selector) {
return $(selector).data('form-object');
},
validate: function(selector, force) {
if ($(selector).length === 0) {
return false;
}
if (!force) {
force = false;
}
return app.sandbox.form.getObject(selector).validation.validate(force);
},
isValid: function(selector) {
return app.sandbox.form.getObject(selector).validation.isValid();
},
addField: function(selector, elementSelector) {
return app.sandbox.form.getObject(selector).addField(elementSelector);
},
removeField: function(selector, elementSelector) {
return app.sandbox.form.getObject(selector).removeField(elementSelector);
},
addConstraint: function(selector, elementSelector, constraintName, options) {
app.sandbox.form.getObject(selector).validation.addConstraint(elementSelector, constraintName, options);
},
updateConstraint: function(selector, elementSelector, constraintName, options) {
app.sandbox.form.getObject(selector).validation.updateConstraint(elementSelector, constraintName, options);
},
deleteConstraint: function(selector, elementSelector, constraintName) {
app.sandbox.form.getObject(selector).validation.deleteConstraint(elementSelector, constraintName);
},
setData: function(selector, data) {
return app.sandbox.form.getObject(selector).mapper.setData(data);
},
getData: function(selector, returnMapperId, $el) {
return app.sandbox.form.getObject(selector).mapper.getData($el, returnMapperId);
},
addToCollection: function(selector, propertyName, data, append) {
return app.sandbox.form.getObject(selector).mapper.addToCollection(propertyName, data, append);
},
editInCollection: function(selector, mapperId, data) {
return app.sandbox.form.getObject(selector).mapper.editInCollection(mapperId, data);
},
removeFromCollection: function(selector, mapperId) {
return app.sandbox.form.getObject(selector).mapper.removeFromCollection(mapperId);
},
addCollectionFilter: function(selector, arrayName, callback) {
app.sandbox.form.getObject(selector).mapper.addCollectionFilter(arrayName, callback);
},
removeCollectionFilter: function(selector, arrayName) {
app.sandbox.form.getObject(selector).mapper.removeCollectionFilter(arrayName);
},
element: {
getObject: function(elementSelector) {
return $(elementSelector).data('element');
},
validate: function(elementSelector, force) {
return app.sandbox.form.element.getObject(elementSelector).validate(force);
},
addConstraint: function(elementSelector, constraintName, options) {
app.sandbox.form.element.getObject(elementSelector).addConstraint(constraintName, options);
},
updateConstraint: function(elementSelector, constraintName, options) {
app.sandbox.form.element.getObject(elementSelector).updateConstraint(constraintName, options);
},
deleteConstraint: function(elementSelector, constraintName) {
app.sandbox.form.element.getObject(elementSelector).deleteConstraint(constraintName);
},
hasConstraint: function(elementSelector, constraintName) {
return app.sandbox.form.element.getObject(elementSelector).hasConstraint(constraintName);
},
getConstraint: function(elementSelector, constraintName) {
return app.sandbox.form.element.getObject(elementSelector).getConstraint(constraintName);
},
setValue: function(elementSelector, value) {
app.sandbox.form.element.getObject(elementSelector).setValue(value);
},
getValue: function(elementSelector) {
return app.sandbox.form.element.getObject(elementSelector).getValue();
}
}
};
}
};
});
})();