Element Select inside of a custom form errors when a file is dragged to it
@andris-sevcenko is already working on this.
Since Jun 26, 2018.
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 705
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 134
Description
Description
I have an ElementSelect field that allows people to upload images inside of SEOmatic, generated via
{{ forms.elementSelect({
id: "seoImageIds",
name: "seoImageIds",
viewMode: "large",
elements: seoImageElements,
elementType: elementType,
criteria: {
kind: ["image"],
},
jsClass: 'Craft.AssetSelectInput',
selectionLabel: "Select SEO Image"|t("seomatic"),
sources: [],
limit: 1,
warning: false,
errors: metaBundleSettings.getErrors("seoImageIds"),
}) }}
This all works fine, unless the user drags an image to that input element, in which case it results in the following error: The field provided is not an Asset field
This appears to come from AssetsController.php around line 87:
if (empty($folderId)) {
$field = Craft::$app->getFields()->getFieldById((int)$fieldId);
if (!($field instanceof AssetsField)) {
throw new BadRequestHttpException('The field provided is not an Assets field');
}
$element = $elementId ? Craft::$app->getElements()->getElementById((int)$elementId) : null;
$folderId = $field->resolveDynamicPathToFolderId($element);
}
Since I'm not passing in an $folderId for the upload destination, I'm assuming this is what triggers it. I guess my question is... is this a bug? The rest of the UX works fine, people can click on the button to choose an image or upload an image without an issue.
Should it be ensuring that the source field type is an AssetsField here? Seems like dragging won't work for custom forms in this case?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.