@osimatic/helpers-js 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/form_helper.js +24 -0
- package/package.json +1 -1
package/form_helper.js
CHANGED
|
@@ -258,6 +258,30 @@ class FormHelper {
|
|
|
258
258
|
return null;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
static extractErrorMessageOfJson(json, onlyIfUniqueError=false) {
|
|
262
|
+
if (typeof json == 'undefined' || json == null) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (typeof json.error != 'undefined') {
|
|
267
|
+
return json.error;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (onlyIfUniqueError && !json.length || json.length > 1) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (typeof json[0] != 'undefined' && typeof json[0].error != 'undefined') {
|
|
275
|
+
return json[0].error;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (typeof json[0] != 'undefined' && Array.isArray(json[0]) && json[0].length === 2) {
|
|
279
|
+
return json[0][1];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
|
|
261
285
|
static hideFormErrors(form) {
|
|
262
286
|
form.find('div.form_errors').remove();
|
|
263
287
|
return form;
|