Skip to content

Commit ff044b0

Browse files
authored
fix(formEnablement): enable required attribute (#5133)
Fixes #3498
1 parent 31a86e2 commit ff044b0

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

packages/main/src/features/InputElementsFormSupport.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@ class FormSupport {
77
* @param nativeInputUpdateCallback - determines how the native input's disabled and value properties are calculated
88
*/
99
static syncNativeHiddenInput(element, nativeInputUpdateCallback) {
10-
const needsNativeInput = !!element.name;
11-
let nativeInput = element.querySelector("input[type=hidden][data-ui5-form-support]");
10+
const needsNativeInput = !!element.name || element.required;
11+
let nativeInput = element.querySelector("input[data-ui5-form-support]");
1212
if (needsNativeInput && !nativeInput) {
1313
nativeInput = document.createElement("input");
14-
nativeInput.type = "hidden";
14+
15+
nativeInput.style.clip = "rect(0 0 0 0)";
16+
nativeInput.style.clipPath = "inset(50%)";
17+
nativeInput.style.height = "1px";
18+
nativeInput.style.overflow = "hidden";
19+
nativeInput.style.position = "absolute";
20+
nativeInput.style.whiteSpace = "nowrap";
21+
nativeInput.style.width = "1px";
22+
nativeInput.style.bottom = "0";
23+
nativeInput.setAttribute("tabindex", "-1");
24+
nativeInput.required = element.required;
1525
nativeInput.setAttribute("data-ui5-form-support", "");
26+
27+
nativeInput.addEventListener("focusin", event => element.focus());
28+
1629
nativeInput.slot = "formSupport"; // Needed for IE - otherwise input elements are not part of the real DOM tree and are not detected by forms
1730
element.appendChild(nativeInput);
1831
}

packages/main/test/pages/form.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@ <h3> Input type 'URL'</h3>
107107
<input type="submit" />
108108
</form>
109109

110+
<form method="get" id="form1">
111+
112+
<ui5-input required>
113+
</ui5-input>
114+
<input required>
115+
110116

117+
<ui5-button submits>Submits forms</ui5-button>
118+
<input type="submit" />
119+
</form>
111120
</body>
112121

113122
</html>

0 commit comments

Comments
 (0)