Skip to content

Commit 27b84a8

Browse files
committed
setup 2 options in the form-options directly for running a validator on first-submission and consequent submissions
1 parent b0dc32c commit 27b84a8

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/form-core/src/FormApi.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,15 @@ export interface FormOptions<
281281
TOnSubmit,
282282
TOnSubmitAsync
283283
>
284+
/**
285+
* Specifies which validation type to use on the first submission attempt
286+
*/
287+
validationOnFirstAttempt?: ValidationCause;
288+
289+
/**
290+
* Specifies which validation type to use on subsequent submission attempts
291+
*/
292+
validationOnConsequentAttempts?: ValidationCause;
284293
/**
285294
* A function to be called when the form is submitted, what should happen once the user submits a valid form returns `any` or a promise `Promise<any>`
286295
*/
@@ -1500,7 +1509,12 @@ export class FormApi<
15001509
this.baseStore.setState((prev) => ({ ...prev, isSubmitting: false }))
15011510
}
15021511

1503-
await this.validateAllFields('submit')
1512+
//
1513+
const validationType = this.state.submissionAttempts === 0
1514+
? this.options.validationOnFirstAttempt ?? 'submit'
1515+
: this.options.validationOnConsequentAttempts ?? 'submit';
1516+
1517+
await this.validateAllFields(validationType)
15041518

15051519
if (!this.state.isFieldsValid) {
15061520
done()
@@ -1511,7 +1525,7 @@ export class FormApi<
15111525
return
15121526
}
15131527

1514-
await this.validate('submit')
1528+
await this.validate(validationType)
15151529

15161530
// Fields are invalid, do not submit
15171531
if (!this.state.isValid) {

0 commit comments

Comments
 (0)