Skip to content

Commit

Permalink
Merge pull request #8 from nighca/disable-validation
Browse files Browse the repository at this point in the history
Debug `disableValidationWhen`
  • Loading branch information
nighca authored Nov 19, 2019
2 parents badf8e4 + c77dada commit 0165645
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formstate-x",
"version": "1.0.3",
"version": "1.0.4",
"description": "Extended alternative for formstate",
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions src/formState.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,16 +871,19 @@ describe('FormState (mode: array) validation', () => {
runInAction(() => options.disabled = true)

await state.validate()
expect(state.$[0].hasError).toBe(false)
expect(state.hasError).toBe(false)
expect(state.error).toBeUndefined()

state.$[0].onChange('')
await state.validate()
expect(state.$[0].hasError).toBe(false)
expect(state.hasError).toBe(false)
expect(state.error).toBeUndefined()

runInAction(() => options.disabled = false)
await delay()
expect(state.$[0].hasError).toBe(true)
expect(state.hasError).toBe(true)
expect(state.error).toBe('empty')

Expand Down
3 changes: 3 additions & 0 deletions src/formState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ export default class FormState<TFields extends ValidatableFields, TValue = Value
*/
@action disableValidationWhen(predict: () => boolean) {
this.shouldDisableValidation = predict
this.fields.forEach(
field => field.disableValidationWhen(predict)
)
return this
}

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface ComposibleValidatable<T, TValue = T> extends Validatable<T, TVa
dirty: boolean
_activated: boolean
_validateStatus: ValidateStatus
disableValidationWhen: (predict: () => boolean) => this
}

/** Function to do dispose. */
Expand Down

0 comments on commit 0165645

Please sign in to comment.