Revision 71d45396
Von Sven Schöling vor etwa 1 Jahr hinzugefügt
js/kivi.Validator.js | ||
---|---|---|
33 | 33 |
}; |
34 | 34 |
|
35 | 35 |
ns.validate = function($e) { |
36 |
/* |
|
36 | 37 |
var $e_annotate; |
37 | 38 |
if ($e.data('ckeditorInstance')) { |
38 | 39 |
$e_annotate = $($e.data('ckeditorInstance').editable().$); |
39 | 40 |
if ($e.data('title')) |
40 | 41 |
$e_annotate.data('title', $e.data('title')); |
41 |
} |
|
42 |
}*/
|
|
42 | 43 |
var tests = $e.data('validate').split(/ +/); |
43 | 44 |
|
44 | 45 |
for (var test_idx in tests) { |
... | ... | |
47 | 48 |
continue; |
48 | 49 |
|
49 | 50 |
if (ns.checks[test]) { |
50 |
if (!ns.checks[test]($e, $e_annotate))
|
|
51 |
if (!ns.checks[test]($e)) |
|
51 | 52 |
return false; |
52 | 53 |
} else { |
53 | 54 |
var error = "kivi.validate_form: unknown test '" + test + "' for element ID '" + $e.prop('id') + "'"; |
... | ... | |
60 | 61 |
return true; |
61 | 62 |
} |
62 | 63 |
|
64 |
ns.val = function($e, data) { |
|
65 |
if ($e.data('ckeditorInstance')) { |
|
66 |
if (data === undefined) |
|
67 |
return $e.data('ckeditorInstance').getData() |
|
68 |
else |
|
69 |
$e.data('ckeditorInstance').setData(data) |
|
70 |
} else { |
|
71 |
if (data === undefined) |
|
72 |
return $e.val(); |
|
73 |
else |
|
74 |
$e.val(data); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
63 | 78 |
ns.checks = { |
64 | 79 |
required: function($e, $e_annotate) { |
65 | 80 |
$e_annotate = $e_annotate || $e; |
66 | 81 |
|
67 |
if ($e.val() === '') {
|
|
82 |
if (ns.val($e) === '') {
|
|
68 | 83 |
ns.annotate($e_annotate, kivi.t8("This field must not be empty.")); |
69 | 84 |
return false; |
70 | 85 |
} else { |
... | ... | |
75 | 90 |
number: function($e, $e_annotate) { |
76 | 91 |
$e_annotate = $e_annotate || $e; |
77 | 92 |
|
78 |
var number_string = $e.val();
|
|
93 |
var number_string = ns.val($e);
|
|
79 | 94 |
|
80 | 95 |
var parsed_number = kivi.parse_amount(number_string); |
81 | 96 |
|
82 | 97 |
if (parsed_number === null) { |
83 |
$e.val('');
|
|
98 |
ns.val($e, '');
|
|
84 | 99 |
ns.annotate($e_annotate); |
85 | 100 |
return true; |
86 | 101 |
} else |
... | ... | |
91 | 106 |
{ |
92 | 107 |
var formatted_number = kivi.format_amount(parsed_number); |
93 | 108 |
if (formatted_number != number_string) |
94 |
$e.val(formatted_number);
|
|
109 |
ns.val($e, formatted_number);
|
|
95 | 110 |
ns.annotate($e_annotate); |
96 | 111 |
return true; |
97 | 112 |
} |
... | ... | |
99 | 114 |
date: function($e, $e_annotate) { |
100 | 115 |
$e_annotate = $e_annotate || $e; |
101 | 116 |
|
102 |
var date_string = $e.val();
|
|
117 |
var date_string = ns.val($e);
|
|
103 | 118 |
|
104 | 119 |
var parsed_date = kivi.parse_date(date_string); |
105 | 120 |
|
106 | 121 |
if (parsed_date === null) { |
107 |
$e.val('');
|
|
122 |
ns.val($e, '');
|
|
108 | 123 |
ns.annotate($e_annotate); |
109 | 124 |
return true; |
110 | 125 |
} else |
... | ... | |
115 | 130 |
{ |
116 | 131 |
var formatted_date = kivi.format_date(parsed_date); |
117 | 132 |
if (formatted_date != date_string) |
118 |
$e.val(formatted_date);
|
|
133 |
ns.val($e, formatted_date);
|
|
119 | 134 |
ns.annotate($e_annotate); |
120 | 135 |
return true; |
121 | 136 |
} |
... | ... | |
123 | 138 |
time: function($e, $e_annotate) { |
124 | 139 |
$e_annotate = $e_annotate || $e; |
125 | 140 |
|
126 |
var time_string = $e.val();
|
|
141 |
var time_string = ns.val($e);
|
|
127 | 142 |
|
128 | 143 |
var parsed_time = kivi.parse_time(time_string); |
129 | 144 |
if (parsed_time === null) { |
130 |
$e.val('');
|
|
145 |
ns.val($e, '');
|
|
131 | 146 |
ns.annotate($e_annotate); |
132 | 147 |
return true; |
133 | 148 |
} else |
... | ... | |
138 | 153 |
{ |
139 | 154 |
var formatted_time = kivi.format_time(parsed_time); |
140 | 155 |
if (formatted_time != time_string) |
141 |
$e.val(formatted_time);
|
|
156 |
ns.val($e, formatted_time);
|
|
142 | 157 |
ns.annotate($e_annotate); |
143 | 158 |
return true; |
144 | 159 |
} |
... | ... | |
146 | 161 |
trimmed_whitespaces: function($e, $e_annotate) { |
147 | 162 |
$e_annotate = $e_annotate || $e; |
148 | 163 |
|
149 |
var string = $e.val();
|
|
164 |
var string = ns.val($e);
|
|
150 | 165 |
|
151 | 166 |
if ($e.hasClass('tooltipstered')) |
152 | 167 |
$e.tooltipster('destroy'); |
153 | 168 |
|
154 | 169 |
if (string.match(/^\s|\s$/)) { |
155 |
$e.val(string.trim());
|
|
170 |
ns.val($e, string.trim());
|
|
156 | 171 |
|
157 | 172 |
$e.tooltipster({ |
158 | 173 |
content: kivi.t8("Leading and trailing whitespaces have been removed."), |
... | ... | |
166 | 181 |
}; |
167 | 182 |
|
168 | 183 |
ns.annotate = function($e, error) { |
184 |
// if element is ckeditor: |
|
185 |
if ($e.data('ckeditorInstance')) { |
|
186 |
const $orig_e = $e; |
|
187 |
$e = $($orig_e.data('ckeditorInstance').ui.view.editable._editableElement); |
|
188 |
if ($orig_e.data('title')) |
|
189 |
$e.data('title', $orig_e.data('title')); |
|
190 |
} |
|
191 |
|
|
169 | 192 |
if (error) { |
170 | 193 |
$e.addClass('kivi-validator-invalid'); |
171 | 194 |
if ($e.hasClass('tooltipstered')) |
Auch abrufbar als: Unified diff
ckeditor5: tooltip Positionierung bei validator checks
Da der ckeditor5 die Werte aus dem Editor nur direkt vor dem submit
zurückkopiert, müssen validation checks auf dem editable Element vom
ckeditor passieren. Da das ein <div> ist, funktioniert das simple
$e.val() nicht mehr, wie Bernd in 4cc35cdc3c auch schon festgestellt
hat.
Es gibt jetzt eine neue kivi.Validator.val($e, data), die statdessen auf
normalen Elementen und auf <textarea> mit ckeditor das Richtige tut.