-
Notifications
You must be signed in to change notification settings - Fork 537
Introduction of the Form component
#2474
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
Conversation
|
I think dots should also be supported for nested data <template>
<Form action="/reports" method="post">
<input type="text" name="name" />
<textarea name="report.description"></textarea>
<input type="text" name="report.tags.0" />
<input type="text" name="report.tags.1" />
<input type="text" name="report.tags.2" />
<input type="file" name="documents" multiple />
<button type="submit">Create Report</button>
</Form>
</template>This is much easier to read and will also make it consistent with the error keys |
|
@laserhybiz Thanks, I'll look into that! Supporting that wouldn't be terribly hard, but I'm more concerned about people wanting to submit field names containing an actual literal period. Maybe we should support escaping it like the validator does: https://laravel.com/index.php/docs/12.x/validation#a-note-on-nested-attributes |
|
@pascalbaljet Thanks for your reply, never knew Laravel has this escaping syntax |
082150d to
34baeee
Compare
This reverts commit 34baeee.
|
Alright, dotted keys are now supported along with escaping dots: <input type="text" name="user.name" placeholder="User Name" />
<input type="text" name="user.profile.city" placeholder="City" />
<input type="text" name="config\.app\.name" placeholder="App Name" />Also, the |
|
Is it possible to integrate this form component with yup library for additional live frontend verification? That will be perfect for me. I'm currently using Formik but it's already irritating me. For complex forms of course. |
|
It would also be nice to migrate the Inertia useForm helper from the Laravel Precognition package to a dedicated <PrecognitiveForm> component if possible! |
Form Component
Basic Usage
At its simplest, the
<Form>component behaves much like a classic HTML form:It also supports more advanced use cases, including nested data structures and file uploads:
Form data is gathered using a
FormDatainstance and then converted to a plain JavaScript object. This lets the form track its dirty state and, when submitting aGETrequest, merge the data into the query string automatically.You can also pass a
transformprop to modify the form data before submission. This is great for injecting extra fields, although hidden inputs work too:Slot Props
Just like the
useForm()helper, the<Form>component exposes reactive state and helpers through its default slot:Options
In addition to
actionandmethod, the<Form>component accepts several props. Many of them are identical to the ones available in Inertia'sVisitOptions:Some props are intentionally grouped under
optionsinstead of being top-level, to avoid confusion. For example,only,except, andresetrelate to partial reloads, not partial submissions. The general rule: top-level props are for the form submission itself, whileoptionscontrol how Inertia handles the next visit.Events
The
<Form>component emits the same events asuseForm(), except the ones related to prefetching: