@ziadshalaby/ngx-zs-component 3.1.1 → 3.1.2
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.
|
@@ -1264,12 +1264,14 @@ class Form {
|
|
|
1264
1264
|
// ==============================================
|
|
1265
1265
|
// Form State & Validation
|
|
1266
1266
|
// ==============================================
|
|
1267
|
-
allFilled =
|
|
1268
|
-
return Object.
|
|
1269
|
-
|
|
1270
|
-
|
|
1267
|
+
allFilled(allowEmptyFields = []) {
|
|
1268
|
+
return Object.keys(this.fields).every((key) => {
|
|
1269
|
+
if (allowEmptyFields.includes(key))
|
|
1270
|
+
return true;
|
|
1271
|
+
const val = this.fields[key]()?.value;
|
|
1272
|
+
return val !== null && val !== undefined && val !== '';
|
|
1271
1273
|
});
|
|
1272
|
-
}
|
|
1274
|
+
}
|
|
1273
1275
|
markAllTouched() {
|
|
1274
1276
|
this.touched.set(true);
|
|
1275
1277
|
}
|
|
@@ -1294,12 +1296,11 @@ class Form {
|
|
|
1294
1296
|
}
|
|
1295
1297
|
return result;
|
|
1296
1298
|
}
|
|
1297
|
-
submit(callback,
|
|
1299
|
+
submit(callback, allowEmptyFields = []) {
|
|
1298
1300
|
this.markAllTouched();
|
|
1299
|
-
const
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
if ((!submitWhenAllNotFilled && !allFilled) || !allValid)
|
|
1301
|
+
const allValid = Object.values(this.getValidations()).every(Boolean);
|
|
1302
|
+
const allFilled = this.allFilled(allowEmptyFields);
|
|
1303
|
+
if (!allFilled || !allValid)
|
|
1303
1304
|
return;
|
|
1304
1305
|
callback(this.getValues());
|
|
1305
1306
|
}
|