magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Form UI Component cannot be used in frontend #38437

Open ioweb-gr opened 9 months ago

ioweb-gr commented 9 months ago

Summary

As it's recommended to use the ui components as much as possible, I wanted to implement a form in the frontend but I'm experiencing a lot of issues.

When trying to use the form component in the frontend I see the following issues.

  1. The <buttons> argument cannot be used directly as it's focused on the admin toolbar. Therefore if you use it, the button won't render. Therefore you have to add the button directly in the fields like this
        <button name="save">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="buttonClasses" xsi:type="string">custom-button-class</item>
                    <item name="actions" xsi:type="array">
                        <item name="0" xsi:type="array">
                            <item name="targetName" xsi:type="string">myform.myform</item>
                            <item name="actionName" xsi:type="string">save</item>
                        </item>
                    </item>
                </item>
            </argument>
            <settings>
                <title translate="true">Save</title>
            </settings>
        </button>

To trigger the save action via the targetName and actionName.

Normally it would be rendered due to Magento_Backend::pageactions.phtml but this block is not available in frontend

  1. The required attributes are not honored, the form can be submitted without any form of validation image

  2. The form key is not added properly causing an error image

Basically it seems the form component is only usable in admin area and not frontend but it's listed under frontend core ui components on the docs.

https://developer.adobe.com/commerce/frontend-core/ui-components/components/form/

I'm not sure if anyone noticed this but either it should be marked as admin ui component and moved away from that section on the docs or it should be fixed to work properly on the frontend.

The example from the docs won't work either in the frontend.

Therefore the only option left to the developer is left with is to render the form fields directly in the frontend on a phtml file and leverage the mage validation tools directly in the phtml file as it's not possible to use the UI component itself that should be usable according to the docs.

Examples

Here's a sample module with a custom form at URL

<example.com>/myform/render/index

myform.zip

Proposed solution

  1. Fix the UI component to work in the frontend or
  2. Remove it from the frontend ui compoments as it's not usable.

Release note

No response

Triage and priority

m2-assistant[bot] commented 9 months ago

Hi @ioweb-gr. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

m2-assistant[bot] commented 9 months ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Hotel commented 9 months ago

Hello @ioweb-gr,

Thanks for the report and collaboration!

We have tried to reproduce the issue in 2.4-develop branch and the issue is reproducible for us. Hence confirming the issue.

Thanks

github-jira-sync-bot commented 9 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-11019 is successfully created for this GitHub issue.

m2-assistant[bot] commented 9 months ago

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

ioweb-gr commented 6 months ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 6 months ago

Hi @ioweb-gr. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 6 months ago

Hi @ioweb-gr, here is your Magento Instance: https://5246d4f5953b869513ffc67af480e773.instances-prod.magento-community.engineering Admin access: https://5246d4f5953b869513ffc67af480e773.instances-prod.magento-community.engineering/admin_431d Login: 6136ef16 Password: 79bfb484e146