Revision 4cc35cdc
Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt
js/kivi.Validator.js | ||
---|---|---|
33 | 33 |
}; |
34 | 34 |
|
35 | 35 |
ns.validate = function($e) { |
36 |
var $e_annotate; |
|
37 |
if ($e.data('ckeditorInstance')) { |
|
38 |
$e_annotate = $($e.data('ckeditorInstance').editable().$); |
|
39 |
if ($e.data('title')) |
|
40 |
$e_annotate.data('title', $e.data('title')); |
|
41 |
} |
|
36 | 42 |
var tests = $e.data('validate').split(/ +/); |
37 | 43 |
|
38 | 44 |
for (var test_idx in tests) { |
... | ... | |
41 | 47 |
continue; |
42 | 48 |
|
43 | 49 |
if (ns.checks[test]) { |
44 |
if (!ns.checks[test]($e)) |
|
50 |
if (!ns.checks[test]($e, $e_annotate))
|
|
45 | 51 |
return false; |
46 | 52 |
} else { |
47 | 53 |
var error = "kivi.validate_form: unknown test '" + test + "' for element ID '" + $e.prop('id') + "'"; |
... | ... | |
55 | 61 |
} |
56 | 62 |
|
57 | 63 |
ns.checks = { |
58 |
required: function($e) { |
|
64 |
required: function($e, $e_annotate) { |
|
65 |
$e_annotate = $e_annotate || $e; |
|
66 |
|
|
59 | 67 |
if ($e.val() === '') { |
60 |
ns.annotate($e, kivi.t8("This field must not be empty.")); |
|
68 |
ns.annotate($e_annotate, kivi.t8("This field must not be empty."));
|
|
61 | 69 |
return false; |
62 | 70 |
} else { |
63 |
ns.annotate($e); |
|
71 |
ns.annotate($e_annotate);
|
|
64 | 72 |
return true; |
65 | 73 |
} |
66 | 74 |
}, |
67 |
number: function($e) { |
|
75 |
number: function($e, $e_annotate) { |
|
76 |
$e_annotate = $e_annotate || $e; |
|
77 |
|
|
68 | 78 |
var number_string = $e.val(); |
69 | 79 |
|
70 | 80 |
var parsed_number = kivi.parse_amount(number_string); |
71 | 81 |
|
72 | 82 |
if (parsed_number === null) { |
73 | 83 |
$e.val(''); |
74 |
ns.annotate($e); |
|
84 |
ns.annotate($e_annotate);
|
|
75 | 85 |
return true; |
76 | 86 |
} else |
77 | 87 |
if (parsed_number === undefined) { |
78 |
ns.annotate($e, kivi.t8('Wrong number format (#1)', [ kivi.myconfig.numberformat ])); |
|
88 |
ns.annotate($e_annotate, kivi.t8('Wrong number format (#1)', [ kivi.myconfig.numberformat ]));
|
|
79 | 89 |
return false; |
80 | 90 |
} else |
81 | 91 |
{ |
82 | 92 |
var formatted_number = kivi.format_amount(parsed_number); |
83 | 93 |
if (formatted_number != number_string) |
84 | 94 |
$e.val(formatted_number); |
85 |
ns.annotate($e); |
|
95 |
ns.annotate($e_annotate);
|
|
86 | 96 |
return true; |
87 | 97 |
} |
88 | 98 |
}, |
89 |
date: function($e) { |
|
99 |
date: function($e, $e_annotate) { |
|
100 |
$e_annotate = $e_annotate || $e; |
|
101 |
|
|
90 | 102 |
var date_string = $e.val(); |
91 | 103 |
|
92 | 104 |
var parsed_date = kivi.parse_date(date_string); |
93 | 105 |
|
94 | 106 |
if (parsed_date === null) { |
95 | 107 |
$e.val(''); |
96 |
ns.annotate($e); |
|
108 |
ns.annotate($e_annotate);
|
|
97 | 109 |
return true; |
98 | 110 |
} else |
99 | 111 |
if (parsed_date === undefined) { |
100 |
ns.annotate($e, kivi.t8('Wrong date format (#1)', [ kivi.myconfig.dateformat ])); |
|
112 |
ns.annotate($e_annotate, kivi.t8('Wrong date format (#1)', [ kivi.myconfig.dateformat ]));
|
|
101 | 113 |
return false; |
102 | 114 |
} else |
103 | 115 |
{ |
104 | 116 |
var formatted_date = kivi.format_date(parsed_date); |
105 | 117 |
if (formatted_date != date_string) |
106 | 118 |
$e.val(formatted_date); |
107 |
ns.annotate($e); |
|
119 |
ns.annotate($e_annotate);
|
|
108 | 120 |
return true; |
109 | 121 |
} |
110 | 122 |
}, |
111 |
time: function($e) { |
|
123 |
time: function($e, $e_annotate) { |
|
124 |
$e_annotate = $e_annotate || $e; |
|
125 |
|
|
112 | 126 |
var time_string = $e.val(); |
113 | 127 |
|
114 | 128 |
var parsed_time = kivi.parse_time(time_string); |
115 | 129 |
if (parsed_time === null) { |
116 | 130 |
$e.val(''); |
117 |
ns.annotate($e); |
|
131 |
ns.annotate($e_annotate);
|
|
118 | 132 |
return true; |
119 | 133 |
} else |
120 | 134 |
if (parsed_time === undefined) { |
121 |
ns.annotate($e, kivi.t8('Wrong time format (#1)', [ kivi.myconfig.timeformat ])); |
|
135 |
ns.annotate($e_annotate, kivi.t8('Wrong time format (#1)', [ kivi.myconfig.timeformat ]));
|
|
122 | 136 |
return false; |
123 | 137 |
} else |
124 | 138 |
{ |
125 | 139 |
var formatted_time = kivi.format_time(parsed_time); |
126 | 140 |
if (formatted_time != time_string) |
127 | 141 |
$e.val(formatted_time); |
128 |
ns.annotate($e); |
|
142 |
ns.annotate($e_annotate);
|
|
129 | 143 |
return true; |
130 | 144 |
} |
131 | 145 |
} |
Auch abrufbar als: Unified diff
js-Validator: Workaround, um Meldung für ckeditor am richtigen Platz anzuzeigen
Da das eigentliche Element, bei dem man im HTMl-Template data-validate
setzt, beim ckeditor nicht sichtbar ist, erschien der Tooltiop irgendwo anders.
Gerne hätte ich in kivi.js (init_text_editor) die data-Attribute
"validate" und "title" auf das "editable" vom ckeditor verschoben
und kivi.Validate so gelassen.
Aber das "editable" ist ein div-Element und die Funktion val() enthält nicht
den Text im Editor, weshalb dann die Prüfung nicht funktioniert.
Deshalb wird nun in kivi.Validate bei einem ckeditor das Element, bei dem die
Annotation erfolgt, auf das "editable" gesetzt.