You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.0 KiB

2 years ago
  1. from typing import Mapping
  2. from gooey import Events
  3. from gooey.python_bindings.types import Try
  4. from gooey.util.functional import merge
  5. def validateForm(self) -> Try[Mapping[str, str]]: # or Exception
  6. config = self.navbar.getActiveConfig()
  7. localErrors: Mapping[str, str] = config.getErrors()
  8. dynamicResult: Try[Mapping[str, str]] = self.fetchDynamicValidations()
  9. combineErrors = lambda m: merge(localErrors, m)
  10. return dynamicResult.map(combineErrors)
  11. def fetchDynamicValidations(self) -> Try[Mapping[str, str]]:
  12. # only run the dynamic validation if the user has
  13. # specifically subscribed to that event
  14. if Events.VALIDATE_FORM in self.buildSpec.get('use_events', []):
  15. cmd = self.getCommandDetails()
  16. return seeder.communicate2(cli.formValidationCmd(
  17. cmd.target,
  18. cmd.subcommand + 'baba',
  19. cmd.positionals,
  20. cmd.optionals
  21. ), self.buildSpec['encoding'])
  22. else:
  23. # shim response if nothing to do.
  24. return Success({})