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

DefaultCommand: Not working for button outside (but linked to) form #11814

Open
BjornJaspers opened this issue Apr 25, 2024 · 2 comments · May be fixed by #11878
Open

DefaultCommand: Not working for button outside (but linked to) form #11814

BjornJaspers opened this issue Apr 25, 2024 · 2 comments · May be fixed by #11878
Assignees
Labels
🐞 defect Bug...Something isn't working
Milestone

Comments

@BjornJaspers
Copy link

BjornJaspers commented Apr 25, 2024

Describe the bug

The DefaultCommand component only works when it targets CommandButtons that are linked to (using the form-attribute), but placed outside the form. See reproducer.

I'm not entirely sure if this should be classified as a bug or not, but I thought it would make sense if this usage would be supported (it sure would help in my use-case).

I already looked through the code and noticed that it indeed doesn't take into account buttons that are not placed inside the form, it only takes into account the form that is actualy enclosed by the target button:

If possible I'd like to contribute with a fix for this!

Reproducer

In the reproducer I created a form with an InputText, CommandButton "Submit inside form" and DefaultCommand. Next to the form there's another CommandButton "Submit outside form" that is linked to the form using the form-attribute. I configured the DefaultCommand to point to button "Submit outside form", but when I press the Enter-key when my focus is in the InputText, the form is submitted using button "Submit inside form".

PrimeFaces_DefaultCommand_reproducer.zip

Relevant portion from reproducer:

<h:form id="frmTest">
    <p:inputText value="#{testView.inputValue}" />
    <p:commandButton id="buttonInsideForm" value="Submit inside form" action="#{testView.submitActionFromInsideForm}" />
    <p:defaultCommand target="buttonOutsideForm" />
</h:form>

<p:commandButton id="buttonOutsideForm" value="Submit outside form" action="#{testView.submitActionFromOutsideForm}" form="frmTest" />

Expected behavior

When pressing the enter key in the InputText, the form should be submitted by button "Submit outside form", as configured in the DefaultCommand component.

PrimeFaces edition

Community

PrimeFaces version

13.0.8

Theme

No response

JSF implementation

All

JSF version

2.3

Java version

17

Browser(s)

No response

@BjornJaspers BjornJaspers added ‼️ needs-triage Issue needs triaging 🐞 defect Bug...Something isn't working labels Apr 25, 2024
@melloware
Copy link
Member

Hmmm this is quite and odd use case. If you submit a PR we can review and discuss...

@melloware melloware added discussion Item needs to be discussed by core devs and removed ‼️ needs-triage Issue needs triaging labels Apr 25, 2024
BjornJaspers added a commit to BjornJaspers/primefaces that referenced this issue May 5, 2024
BjornJaspers added a commit to BjornJaspers/primefaces that referenced this issue May 5, 2024
…port submit buttons that are placed outside (but linked to) the form
@BjornJaspers
Copy link
Author

Finally I found some time to create a PR with the fix I had in mind: #11878

@melloware melloware added this to the 15.0.0 milestone May 5, 2024
@melloware melloware removed the discussion Item needs to be discussed by core devs label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 defect Bug...Something isn't working
Projects
None yet
2 participants