Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.x] Remove data option from useForm options type #2060

Merged
merged 4 commits into from
Jan 9, 2025
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
15 changes: 8 additions & 7 deletions packages/react/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import useRemember from './useRemember'
type setDataByObject<TForm> = (data: TForm) => void
type setDataByMethod<TForm> = (data: (previousData: TForm) => TForm) => void
type setDataByKeyValuePair<TForm> = <K extends keyof TForm>(key: K, value: TForm[K]) => void
type FormDataType = object
type FormDataType = Record<string, FormDataConvertible>
type FormOptions = Omit<VisitOptions, 'data'>

export interface InertiaFormProps<TForm extends FormDataType> {
data: TForm
Expand All @@ -26,12 +27,12 @@ export interface InertiaFormProps<TForm extends FormDataType> {
clearErrors: (...fields: (keyof TForm)[]) => void
setError(field: keyof TForm, value: string): void
setError(errors: Record<keyof TForm, string>): void
submit: (method: Method, url: string, options?: VisitOptions) => void
get: (url: string, options?: VisitOptions) => void
patch: (url: string, options?: VisitOptions) => void
post: (url: string, options?: VisitOptions) => void
put: (url: string, options?: VisitOptions) => void
delete: (url: string, options?: VisitOptions) => void
submit: (method: Method, url: string, options?: FormOptions) => void
get: (url: string, options?: FormOptions) => void
patch: (url: string, options?: FormOptions) => void
post: (url: string, options?: FormOptions) => void
put: (url: string, options?: FormOptions) => void
delete: (url: string, options?: FormOptions) => void
cancel: () => void
}
export default function useForm<TForm extends FormDataType>(initialValues?: TForm): InertiaFormProps<TForm>
Expand Down
15 changes: 8 additions & 7 deletions packages/svelte/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import isEqual from 'lodash/isEqual'
import { writable, type Writable } from 'svelte/store'

type FormDataType = Record<string, FormDataConvertible>
type FormOptions = Omit<VisitOptions, 'data'>

export interface InertiaFormProps<TForm extends FormDataType> {
isDirty: boolean
Expand All @@ -36,12 +37,12 @@ export interface InertiaFormProps<TForm extends FormDataType> {
clearErrors(...fields: (keyof TForm)[]): this
setError(field: keyof TForm, value: string): this
setError(errors: Errors): this
submit(method: Method, url: string, options?: Partial<VisitOptions>): void
get(url: string, options?: Partial<VisitOptions>): void
post(url: string, options?: Partial<VisitOptions>): void
put(url: string, options?: Partial<VisitOptions>): void
patch(url: string, options?: Partial<VisitOptions>): void
delete(url: string, options?: Partial<VisitOptions>): void
submit(method: Method, url: string, options?: FormOptions): void
get(url: string, options?: FormOptions): void
post(url: string, options?: FormOptions): void
put(url: string, options?: FormOptions): void
patch(url: string, options?: FormOptions): void
delete(url: string, options?: FormOptions): void
cancel(): void
}

Expand Down Expand Up @@ -140,7 +141,7 @@ export default function useForm<TForm extends FormDataType>(
)
return this
},
submit(method, url, options: Partial<VisitOptions> = {}) {
submit(method, url, options: FormOptions = {}) {
const data = transform(this.data()) as RequestPayload
const _options: Omit<VisitOptions, 'method'> = {
...options,
Expand Down
17 changes: 9 additions & 8 deletions packages/vue3/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import cloneDeep from 'lodash.clonedeep'
import isEqual from 'lodash.isequal'
import { reactive, watch } from 'vue'

type FormDataType = object
type FormDataType = Record<string, FormDataConvertible>
type FormOptions = Omit<VisitOptions, 'data'>

interface InertiaFormProps<TForm extends FormDataType> {
isDirty: boolean
Expand All @@ -22,12 +23,12 @@ interface InertiaFormProps<TForm extends FormDataType> {
clearErrors(...fields: (keyof TForm)[]): this
setError(field: keyof TForm, value: string): this
setError(errors: Record<keyof TForm, string>): this
submit(method: Method, url: string, options?: Partial<VisitOptions>): void
get(url: string, options?: Partial<VisitOptions>): void
post(url: string, options?: Partial<VisitOptions>): void
put(url: string, options?: Partial<VisitOptions>): void
patch(url: string, options?: Partial<VisitOptions>): void
delete(url: string, options?: Partial<VisitOptions>): void
submit(method: Method, url: string, options?: FormOptions): void
get(url: string, options?: FormOptions): void
post(url: string, options?: FormOptions): void
put(url: string, options?: FormOptions): void
patch(url: string, options?: FormOptions): void
delete(url: string, options?: FormOptions): void
cancel(): void
}

Expand Down Expand Up @@ -126,7 +127,7 @@ export default function useForm<TForm extends FormDataType>(

return this
},
submit(method, url, options: VisitOptions = {}) {
submit(method, url, options: FormOptions = {}) {
const data = transform(this.data())
const _options = {
...options,
Expand Down
Loading