forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug(@ionic/core): Implicit form submit doesn't work in Ionic 4
Fixes ionic-team#15682 Pressing enter key on input & textarea now submits the form Also fixed one build issue regarding a type error related to `SelectInputChangeEvent`
- Loading branch information
Showing
8 changed files
with
113 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html dir="ltr"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Input - Form Submit</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> | ||
<script src="/dist/ionic.js"></script> | ||
<link rel="stylesheet" type="text/css" href="/css/ionic.bundle.css"> | ||
</head> | ||
|
||
<body> | ||
<ion-app> | ||
|
||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Input - Form Submit</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
|
||
<ion-content id="content"> | ||
<form> | ||
<ion-list> | ||
<ion-item> | ||
<ion-label color="primary">Input</ion-label> | ||
<ion-input></ion-input> | ||
</ion-item> | ||
<div padding> | ||
<ion-button expand="block" type="submit">Submit</ion-button> | ||
</div> | ||
</ion-list> | ||
</form> | ||
</ion-content> | ||
</ion-app> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html dir="ltr"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Textarea - Form Submit</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> | ||
<script src="/dist/ionic.js"></script> | ||
<link rel="stylesheet" type="text/css" href="/css/ionic.bundle.css"> | ||
</head> | ||
|
||
<body> | ||
<ion-app> | ||
|
||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Textarea - Form Submit</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
|
||
<ion-content id="content"> | ||
<form> | ||
<ion-list> | ||
<ion-item> | ||
<ion-label color="primary">Textarea</ion-label> | ||
<ion-textarea></ion-textarea> | ||
</ion-item> | ||
<div padding> | ||
<ion-button expand="block" type="submit">Submit</ion-button> | ||
</div> | ||
</ion-list> | ||
</form> | ||
</ion-content> | ||
</ion-app> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { hasShadowDom } from './helpers'; | ||
|
||
export const KEY_CODES = { | ||
ENTER: 13 | ||
}; | ||
|
||
export function submitFormOnEnterPress(el: HTMLElement, ev: KeyboardEvent) { | ||
const form = el.closest('form'); | ||
if (form) { | ||
ev.stopPropagation(); | ||
const submitButton: HTMLElement | null = form.querySelector('[type="submit"]'); | ||
if (submitButton) { | ||
if (hasShadowDom(submitButton)) { | ||
const fakeButton = document.createElement('button'); | ||
fakeButton.type = 'submit'; | ||
fakeButton.style.display = 'none'; | ||
form.appendChild(fakeButton); | ||
console.log(form); | ||
fakeButton.click(); | ||
fakeButton.remove(); | ||
} else { | ||
submitButton.click(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters