summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/validators/file-validator.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/validators/file-validator.ts')
-rw-r--r--src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/validators/file-validator.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/validators/file-validator.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/validators/file-validator.ts
new file mode 100644
index 000000000..672610422
--- /dev/null
+++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/validators/file-validator.ts
@@ -0,0 +1,15 @@
+import { AbstractControl } from '@angular/forms';
+
+export function formlyAsyncFileValidator(control: AbstractControl): Promise<any> {
+ return new Promise((resolve, _reject) => {
+ if (control.value instanceof FileList) {
+ control.value;
+ let file = control.value[0];
+ if (file.size > 4096) {
+ resolve({ file_size: true });
+ }
+ resolve(null);
+ }
+ resolve({ not_a_file: true });
+ });
+}