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
feat(button): submit from outside of form #25913
feat(button): submit from outside of form #25913
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small suggestion on the documentation (will require a new npm run build
for the generated outputs).
We will also need Playwright tests for this feature.
For example, in core/src/components/button/test/form-reference
create a new button.e2e.ts
file.
You will need to test 3 conditions:
- Form with an ID
- Form as a reference
- No form (querying the closest form).
For these, setting the HTML mark-up per test is probably easiest.
I did not run these tests locally, but something like this:
test.describe('button: form', () => {
test('should submit the form by id', async({ page }) => {
await page.setContent(`
<form id="myForm"></form>
<ion-button form="myForm" type="submit">Submit</ion-button>
`);
const submitEvent = await page.spyOnEvent('submit');
await page.click('ion-button');
expect(submitEvent).toHaveReceivedEvent();
});
test('should submit the form by reference', async({ page }) => {
await page.setContent(`
<form></form>
<ion-button type="submit">Submit</ion-button>
<script>
const form = document.querySelector('form');
const button = document.querySelector('ion-button');
button.form = form;
</script>
`);
const submitEvent = await page.spyOnEvent('submit');
await page.click('ion-button');
expect(submitEvent).toHaveReceivedEvent();
});
test('should submit the closest form', async({ page }) => {
await page.setContent(`
<form>
<ion-button type="submit">Submit</ion-button>
</form>
`);
const submitEvent = await page.spyOnEvent('submit');
await page.click('ion-button');
expect(submitEvent).toHaveReceivedEvent();
});
});
Let me know if you have questions.
@sean-perkins Thanks for the support. But I can't get the tests to run. I've tried all possible commands for testing
|
@postnerd We are in the middle of a transition between two E2E testing systems. The |
Co-authored-by: Sean Perkins <sean@ionic.io>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the required tests.
Please let me know if there is anything else to do.
(Messed up this one commit when adding the tests with a wrong commit message.) Since this is such a small PR I could just create another branch and PR with just one commit if you want me to.)
The commit message is ok here. We will end up squashing the commits anyways, so only the topmost description (the PR title) will matter. I approved CI to run to verify the tests. I don't see any other items requiring changes on my end. If CI passes, I'll add the team and we can discuss the release target for this feature. |
@sean-perkins Is there anything to do from my side because of the failed tests? |
@postnerd merge the latest change from |
Merged again (after @liamdebeasi already merged) because the branch was again one commit behind.
Only one change to angular/src/directives/proxies-list.ts that I've ignored before, because it looks like an unrelated style fix (a strange one, adding a line at the beginning of the file ...). |
Yeah, you can ignore that diff. Running I re-triggered CI to run. |
@postnerd update on our end: The team has drafted and approved a design document around this feature. The only item that is outstanding as a result, is we want to introduce a developer warning when the form cannot be found, when using the I can snag this scope & can commit it directly to your fork. We will target this feature for 6.3 after I make that change & then the team can do a final review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once the comment is addressed 👍
); | ||
} else { | ||
printIonWarning( | ||
`The provided "form" element could not be found. Verify that the form is rendered in the DOM.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning is a bit confusing because it implies that the form element is not in the DOM at all. However, it could be the case that the element is in the DOM but is not an HTMLFormElement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the warning message. Let me know if it is more clear or requires additional adjustment.
Great work here @postnerd 👍 thanks for the contribution! |
Pull request checklist
Please check if your PR fulfills the following requirements:
ionic-docs
repo, in a separate PR. See the contributing guide for details.npm run build
) was run locally and any changes were pushednpm run lint
) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
Buttons with type "submit" will only work from inside forms.
Issue URL: #21194
What is the new behavior?
Now you can add a "form" prop to every that will be used, if the button is placed outside of a form. This can be helpful, if the button is added to a header/footer toolbar but should be responsible for a specific form.
Does this introduce a breaking change?
Other information
Not sure, if the docs have to be updated. If so, I'm happy to do so. Maybe you could guide me to the right place.