Skip to content

Commit 9e5d2f7

Browse files
authored
fix(formvalidation): no error for missing field on autocheck
A followup on #2633 As we centralised the field getter, the error message of a non existing field will occur all the time, even in situations where we definately want to remove field related validation rules if a field is non existing anymore and are aware of that.
1 parent 870970b commit 9e5d2f7

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/definitions/behaviors/form.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@
619619
// refresh selector cache
620620
(instance || module).refresh();
621621
},
622-
field: function (identifier, strict) {
622+
field: function (identifier, strict, ignoreMissing) {
623623
module.verbose('Finding field with identifier', identifier);
624624
identifier = module.escape.string(identifier);
625625
var t;
@@ -639,7 +639,9 @@
639639
if (t.length > 0) {
640640
return t;
641641
}
642-
module.error(error.noField.replace('{identifier}', identifier));
642+
if (!ignoreMissing) {
643+
module.error(error.noField.replace('{identifier}', identifier));
644+
}
643645

644646
return strict ? $() : $('<input/>');
645647
},
@@ -817,10 +819,10 @@
817819

818820
has: {
819821

820-
field: function (identifier) {
822+
field: function (identifier, ignoreMissing) {
821823
module.verbose('Checking for existence of a field with identifier', identifier);
822824

823-
return module.get.field(identifier, true).length > 0;
825+
return module.get.field(identifier, true, ignoreMissing).length > 0;
824826
},
825827

826828
},
@@ -1020,7 +1022,7 @@
10201022
}
10211023
if (rule === undefined) {
10221024
module.debug('Removed all rules');
1023-
if (module.has.field(field)) {
1025+
if (module.has.field(field, true)) {
10241026
validation[field].rules = [];
10251027
} else {
10261028
delete validation[field];
@@ -1221,7 +1223,7 @@
12211223
module.debug('Enabling auto check on required fields');
12221224
if (validation) {
12231225
$.each(validation, function (fieldName) {
1224-
if (!module.has.field(fieldName)) {
1226+
if (!module.has.field(fieldName, true)) {
12251227
module.verbose('Field not found, removing from validation', fieldName);
12261228
module.remove.field(fieldName);
12271229
}

types/fomantic-ui-form.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ declare namespace FomanticUI {
5151
/**
5252
* Returns element with matching name, id, or data-validate metadata to identifier.
5353
*/
54-
(behavior: 'get field', identifier: string): string;
54+
(behavior: 'get field', identifier: string, strict?: boolean, ignoreMissing?: boolean): string;
5555

5656
/**
5757
* Returns value of element with id.
@@ -82,7 +82,7 @@ declare namespace FomanticUI {
8282
/**
8383
* Returns whether a field exists.
8484
*/
85-
(behavior: 'has field', identifier: string): boolean;
85+
(behavior: 'has field', identifier: string, ignoreMissing?: boolean): boolean;
8686

8787
/**
8888
* Manually add errors to form, given an array errors.
@@ -227,7 +227,7 @@ declare namespace FomanticUI {
227227
errorFocus: boolean | string;
228228

229229
/**
230-
*
230+
*
231231
* @default 0
232232
*/
233233
errorLimit: number;
@@ -373,7 +373,7 @@ declare namespace FomanticUI {
373373
*/
374374
leavingMessage: string;
375375
}
376-
376+
377377
interface Prompts {
378378
/**
379379
* @default '{name} must have a value'
@@ -500,7 +500,7 @@ declare namespace FomanticUI {
500500
*/
501501
maxCount: string;
502502
}
503-
503+
504504
interface Formatters {
505505
date(date: string): string;
506506
datetime(date: string): string;

0 commit comments

Comments
 (0)