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

Fix form helper types for setDefaults() method (React) and defaults() method (Vue) #1504

Merged
merged 7 commits into from
Aug 16, 2023
Merged

Conversation

shealavington
Copy link
Contributor

Allows types than strings, based on the type passed in by the implementer.
fixes #1502

Successfully tested locally in my project.

@daleweaver777
Copy link

daleweaver777 commented Jun 6, 2023

I'm running into this issue also. I have typed objects in my useForm and get a typescript error when trying to set defaults because it's expecting a string.

const props = defineProps<{
  workOrder: WorkOrder;
  jobCosts: JobCost[];
}>();

const editForm = useForm({
  workOrder: props.workOrder,
  jobCosts: props.jobCosts,
  deletedJobCosts: new Array<number>(),
});

// this causes a type error because it's expecting strings
editForm.defaults({ workOrder: props.workOrder, jobCosts: props.jobCosts, deletedJobCosts: [] });

Another problem is the typing with the errors property. It doesn't allow for validation errors returned from Laravel for array values being validated. When I submit an array value to Laravel and the validation returns an error for an array field, I can't access the error for the array value in my template using form.errors['jobCosts.1.amount'] without getting a type error.

@thecrypticace thecrypticace self-assigned this Jul 31, 2023
@reinink reinink changed the title Allow user defined types & Export Interface Fix form helper types for setDefaults() method (React) and defaults() method (Vue) Aug 16, 2023
@reinink reinink merged commit 9ebe6e8 into inertiajs:master Aug 16, 2023
4 checks passed
@reinink
Copy link
Member

reinink commented Aug 16, 2023

@shealavington Hey thanks so much for submitting this fix! I've made some further improvements to these types by taking advantage of the FormDataConvertible type that exists in Inertia core.

@reinink
Copy link
Member

reinink commented Aug 18, 2023

These changes have been published in v1.0.11 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Form Defaults: Typescript forced to use strings.
4 participants