Skip to content

Commit

Permalink
Merge branch 'develop' into session-refactor-pt3
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyrohrbough committed May 5, 2022
2 parents a2d6283 + aa6f3b8 commit 896d285
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/driver/cypress/fixtures/dom.html
Expand Up @@ -323,6 +323,12 @@
<button type="submit">submit me</button>
</form>

<form id="multiple-inputs-and-button-submit.outside-form">
<input name="fname" />
<input name="lname" />
</form>
<button form="multiple-inputs-and-button-submit.outside-form" type="submit">submit me</button>

<form id="multiple-inputs-and-reset-and-submit-buttons">
<input name="fname" />
<input name="lname" />
Expand Down
Expand Up @@ -1486,6 +1486,16 @@ describe('src/cy/commands/actions/type - #type special chars', () => {
cy.get('#multiple-inputs-and-button-submit input:first').type('foo{enter}')
})

it('triggers form submit when the submit button is outside of the form', function (done) {
this.$forms.find('[id="multiple-inputs-and-button-submit.outside-form"]').submit((e) => {
e.preventDefault()

done()
})

cy.get('[id="multiple-inputs-and-button-submit.outside-form"] input:first').type('foo{enter}')
})

it('causes click event on the button[type=submit]', function (done) {
this.$forms.find('#multiple-inputs-and-button-submit button[type=submit]').click((e) => {
e.preventDefault()
Expand Down
10 changes: 9 additions & 1 deletion packages/driver/src/cy/commands/actions/type.ts
Expand Up @@ -173,7 +173,15 @@ export default function (Commands, Cypress, cy, state, config) {
const win = state('window')

const getDefaultButtons = (form) => {
return form.find('input, button').filter((__, el) => {
const formId = CSS.escape(form.attr('id'))
const nestedButtons = form.find('input, button')

const possibleDefaultButtons: JQuery<any> = formId ? $dom.wrap(_.uniq([
...nestedButtons,
...$dom.query('body', form.prop('ownerDocument')).find(`input[form="${formId}"], button[form="${formId}"]`),
])) : nestedButtons

return possibleDefaultButtons.filter((__, el) => {
const $el = $dom.wrap(el)

return (
Expand Down

0 comments on commit 896d285

Please sign in to comment.