Skip to content

Commit 9e409e6

Browse files
authoredMar 2, 2021
fix(ui5-input): remove the 'submit' event (#2855)
The 'submit' event fired from the ui5-input component is now removed as it is an event of the 'form' element and not of the input ones. From now on, the submit (event) must be triggered manually when enter key is pressed. BREAKING CHANGE: the 'submit' event is now removed. The 'submit' functionality must be added with a custom code - listen for the standard "keydown" event and check if ENTER is pressed to submit a form, containing the input component.
1 parent c611680 commit 9e409e6

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed
 

‎packages/main/src/Input.js

+1-19
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,6 @@ const metadata = {
372372
*/
373373
input: {},
374374

375-
/**
376-
* Fired when user presses Enter key on the <code>ui5-input</code>.
377-
* <br><br>
378-
* <b>Note:</b> The event is fired independent of whether there was a change before or not.
379-
* If change was performed, the event is fired after the change event.
380-
* The event is also fired when an item of the select list is selected by pressing Enter.
381-
*
382-
* @event
383-
* @public
384-
*/
385-
submit: {},
386-
387375
/**
388376
* Fired when a suggestion item, that is displayed in the suggestion popup, is selected.
389377
*
@@ -521,7 +509,6 @@ class Input extends UI5Element {
521509
this.highlightValue = "";
522510

523511
// all sementic events
524-
this.EVENT_SUBMIT = "submit";
525512
this.EVENT_CHANGE = "change";
526513
this.EVENT_INPUT = "input";
527514
this.EVENT_SUGGESTION_ITEM_SELECT = "suggestion-item-select";
@@ -885,7 +872,6 @@ class Input extends UI5Element {
885872
}
886873

887874
const inputValue = await this.getInputValue();
888-
const isSubmit = action === this.ACTION_ENTER;
889875
const isUserInput = action === this.ACTION_USER_INPUT;
890876

891877
const input = await this.getInputDOMRef();
@@ -910,13 +896,9 @@ class Input extends UI5Element {
910896
return;
911897
}
912898

913-
if (isSubmit) { // submit
914-
this.fireEvent(this.EVENT_SUBMIT);
915-
}
916-
917899
// In IE, pressing the ENTER does not fire change
918900
const valueChanged = (this.previousValue !== undefined) && (this.previousValue !== this.value);
919-
if (isIE() && isSubmit && valueChanged) {
901+
if (isIE() && action === this.ACTION_ENTER && valueChanged) {
920902
this.fireEvent(this.EVENT_CHANGE);
921903
}
922904
}

‎packages/main/src/StepInput.hbs

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
._inputAccInfo ="{{accInfo}}"
4343
._nativeInputAttributes="{{inputAttributes}}"
4444
@ui5-change="{{_onInputChange}}"
45-
@ui5-submit="{{_onInputChange}}"
4645
@focusout="{{_onInputFocusOut}}"
4746
@focusin="{{_onInputFocusIn}}"
4847
>

‎packages/main/src/StepInput.js

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
isPageUpShift,
1212
isPageDownShift,
1313
isEscape,
14+
isEnter,
1415
} from "@ui5/webcomponents-base/dist/Keys.js";
1516
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
1617
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
@@ -566,6 +567,11 @@ class StepInput extends UI5Element {
566567
return;
567568
}
568569

570+
if (isEnter(event)) {
571+
this._onInputChange();
572+
return;
573+
}
574+
569575
if (isUp(event)) {
570576
// step up
571577
this._modifyValue(this.step);

‎packages/main/test/pages/Input.html

+28-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<h3> Input with suggestions: type 'a'</h3>
1919
<ui5-label id="myLabel">Event [suggestionItemSelect] :: N/A</ui5-label><br/>
2020
<ui5-label id="myLabelChange">Event [change] :: N/A</ui5-label><br/>
21-
<ui5-label id="myLabelSubmit">Event [submit] :: N/A</ui5-label><br/>
2221
<ui5-label id="myLabelLiveChange">Event [input] :: N/A</ui5-label><br/>
2322

2423
<div>
@@ -220,6 +219,11 @@ <h3> Input with multiple icons</h3>
220219
<ui5-icon slot="icon" name="decline" style="padding-left: 8px; padding-right: 8px"></ui5-icon>
221220
</ui5-input>
222221

222+
<h3> Input firing submit event and submit action on 'ENTER' in a form</h3>
223+
<form id="submit-form">
224+
<ui5-input id="submit-input" name="my-submit-input" placeholder="Type something and press 'ENTER' ..."></ui5-input>
225+
</form>
226+
223227
<h3> Test scroll pos</h3>
224228
<ui5-input id="scrollInput" show-suggestions>
225229
<ui5-li>Cozy</ui5-li>
@@ -318,6 +322,29 @@ <h3>Short Input With Centered Text</h3>
318322
</style>
319323

320324
<script>
325+
document.getElementById("submit-input").addEventListener("keypress", function(event) {
326+
if (event.key === 'Enter') {
327+
var formToSubmit = document.getElementById("submit-form");
328+
var submitEvent = new Event('submit');
329+
330+
/* The old way - supported by all browsers:
331+
The submit method of the form won't trigger
332+
a submit event by itself, dispatch it manually */
333+
334+
// formToSubmit.dispatchEvent(submitEvent);
335+
// formToSubmit.submit();
336+
337+
// Fires submit event and submits
338+
// No MS IE11 & Safari support yet
339+
formToSubmit.requestSubmit()
340+
}
341+
});
342+
343+
document.getElementById("submit-form").addEventListener("submit", function(event) {
344+
event.preventDefault();
345+
alert("Submitted");
346+
});
347+
321348
btnOpenDialog.addEventListener("click", function () {
322349
dialog.open();
323350
});
@@ -335,7 +362,6 @@ <h3>Short Input With Centered Text</h3>
335362
var label = document.getElementById('myLabel');
336363
var labelChange = document.getElementById('myLabelChange');
337364
var labelLiveChange = document.getElementById('myLabelLiveChange');
338-
var labelSubmit = document.getElementById('myLabelSubmit');
339365

340366
var suggestionSelectedCounterWithGrouping = 0;
341367

@@ -390,10 +416,6 @@ <h3>Short Input With Centered Text</h3>
390416
labelChange.innerHTML = "Event [change] :: " + event.target.value;
391417
});
392418

393-
input.addEventListener("ui5-submit", function (event) {
394-
labelSubmit.innerHTML = "Event [submit] :: " + event.target.value;
395-
});
396-
397419
var changeCounter = 0;
398420
var inputCounter = 0;
399421
var suggestionSelectedCounter = 0;
@@ -416,9 +438,6 @@ <h3>Short Input With Centered Text</h3>
416438

417439
var inputChangeResultCounter = 0;
418440

419-
inputChange.addEventListener("ui5-submit", function (event) {
420-
inputChange.value = "Changed via API";
421-
});
422441
inputChange.addEventListener("ui5-change", function (event) {
423442
inputChangeResult.value = ++inputChangeResultCounter;
424443
});

0 commit comments

Comments
 (0)
Please sign in to comment.