form.ts 946 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type {
  2. VbenFormSchema as FormSchema,
  3. VbenFormProps,
  4. } from '@vben/common-ui';
  5. import type { ComponentType } from './component';
  6. import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui';
  7. import { $t } from '@vben/locales';
  8. setupVbenForm<ComponentType>({
  9. config: {
  10. modelPropNameMap: {
  11. Upload: 'fileList',
  12. },
  13. },
  14. defineRules: {
  15. required: (value, _params, ctx) => {
  16. if (value === undefined || value === null || value.length === 0) {
  17. return $t('ui.formRules.required', [ctx.label]);
  18. }
  19. return true;
  20. },
  21. selectRequired: (value, _params, ctx) => {
  22. if (value === undefined || value === null) {
  23. return $t('ui.formRules.selectRequired', [ctx.label]);
  24. }
  25. return true;
  26. },
  27. },
  28. });
  29. const useVbenForm = useForm<ComponentType>;
  30. export { useVbenForm, z };
  31. export type VbenFormSchema = FormSchema<ComponentType>;
  32. export type { VbenFormProps };