Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/ReactFinalForm.d.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { Form, Field } from './index'
import { Mutator } from 'final-form/dist'

const onSubmit = async (values: any) => {
console.log(values)
Expand Down Expand Up @@ -63,3 +64,36 @@ const simpleSubscription = () => (
)}
</Form>
)

const setValue: Mutator = ([name, newValue], state, { changeValue }) => {
changeValue(state, name, value => newValue)
}

const mutated = () => (
<Form onSubmit={onSubmit} mutators={{ setValue }}>
{({
handleSubmit,
mutators: { setValue },
submitting,
pristine,
values
}) => (
<form onSubmit={handleSubmit}>
<Field
name="firstName"
component="input"
type="text"
placeholder="First Name"
/>
<button
type="button"
onClick={e => setValue('firstName', 'Kevin')}
disabled={submitting || pristine}
>
Reset
</button>
<pre>{JSON.stringify(values)}</pre>
</form>
)}
</Form>
)
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface SubsetFormApi {
change: (name: string, value: any) => void
focus: (name: string) => void
initialize: (values: object) => void
mutators?: { [key: string]: Function }
mutators: { [key: string]: Function }
reset: () => void
}

Expand Down