Closed aldoemir closed 1 month ago
Hello, @aldoemir,
The updateOrCreate
method, which is passed as an argument from the form component, is responsible for handling input fields:
<x-admin::form.control-group.control
type="text"
id="name"
name="name"
/>
or the Vue component:
<v-field></v-field>
However, for the image component, since the input field is created using native HTML, you will need to utilize JavaScript's native FormData
in combination with the $refs
method. This will allow you to capture all input fields, including those in the image component, as shown below:
<x-admin::form
v-slot="{ meta, values, errors, handleSubmit }"
as="div"
>
<form
@submit="handleSubmit($event, updateOrCreate)"
ref="form"
></form>
</x-admin::form>
In your JavaScript method:
updateOrCreate(params, { resetForm, setErrors }) {
let formData = new FormData(this.$refs.form);
}
Using FormData
, you’ll be able to collect data from all input fields, including the image component's input field.
Best regards,
(Suraj)
It worked! But when I'm opening the modal the logo doesn't show up. Here's the meta when I open the edit modal:
{
"initialValues": {
"id": 16,
"name": "asdfg"
},
"touched": false,
"pending": false,
"valid": true,
"dirty": true
}
As you can see, the logo is missing.
Hello, @aldoemir,
To display the uploaded image, you need to pass additional props to the image Blade component. Here's an example:
<x-admin::form.control-group>
<x-admin::media.images
name="image"
::uploaded-images="pathOfImage ? [['id' => 'image', 'url' => pathOfImage]] : []"
/>
</x-admin::form.control-group>
In this example, ::
(double colon) indicates that uploaded-images
is accepting a JavaScript variable, whereas :
(single colon) means it is expecting a PHP variable.
For reference, you can review the code structure in the following file:packages/Webkul/Admin/src/Resources/views/settings/users/index.blade.php
Best regards,
(Suraj)
Thank you for reaching out. It looks like your request is not an issue report. For discussions, questions, or general support, we encourage you to use the Krayin Forum. The forum is the best place for such queries, and you'll be able to connect with other community members and get the help you need.
Please reserve the GitHub issue tracker for reporting bugs and issues with the codebase. This helps us keep the issue tracker focused and ensures that problems are addressed promptly.
Thank you for your understanding!
Bug report
Image not being passed to params in form component
Issue Description
When using the
x-admin::media.images
component the content of it won't be passed to params ofupdateOrCreate
method. I don't think the vee-validate field is implemented inmedia.images
component.,Preconditions
Please provide as detailed information about your environment as possible.
Steps to reproduce
It is important to provide a set of clear steps to reproduce this bug.If relevant please include code samples.
Expected result
Image to be passed to
params
Actual result