-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui5-switch): add required property (#7324)
Introducing the `required` property for the Switch control. We now also enable the Form Support feature within the control, which means now the Switch component, could be easily used and integrated within forms as well.
- Loading branch information
Showing
6 changed files
with
173 additions
and
4 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
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 |
---|---|---|
|
@@ -55,6 +55,28 @@ <h3>Graphical Switch</h3> | |
<ui5-switch design="Graphical" checked text-on="Yes" text-off="No" disabled></ui5-switch> | ||
</div> | ||
|
||
<div class="switch2auto"> | ||
<form id="myForm" class="switch-form"> | ||
<h3 style="margin: 0 0 1rem 0">Switch in Registration form example</h3> | ||
<div style="display: flex; flex-direction: column;"> | ||
<ui5-input required type="Email" placeholder="Email" value="[email protected]"></ui5-input> | ||
<ui5-input required type="Password" placeholder="Password" value="[email protected]"></ui5-input> | ||
</div> | ||
<p style="margin: 1rem 0 0 0">Please accept the terms and conditions, in order to proceed.</p> | ||
<ui5-switch id="requiredSwitch" style="margin: 0" name="switch" text-on="Yes" text-off="No" required></ui5-switch> | ||
<br /> | ||
<ui5-button type="Submit" id="submitBtn">Submit Form</ui5-button> | ||
</form> | ||
</div> | ||
|
||
<h3>Switch in form test</h3> | ||
<form id="switchForm"> | ||
<ui5-switch id="switch1" checked></ui5-switch> | ||
<ui5-switch id="requiredTestSwitch" required></ui5-switch> | ||
<br><br> | ||
<ui5-button id="switchSubmit" type="Submit">Submit</ui5-button> | ||
</form> | ||
|
||
<h3>Custom Switch</h3> | ||
<div class="switch2auto"> | ||
<ui5-switch text-on="Accept" text-off="Reject" class="switch4auto"></ui5-switch> | ||
|
@@ -83,6 +105,13 @@ <h3>sap_horizon</h3> | |
<script> | ||
var counter = 0; | ||
|
||
submitBtn.addEventListener("click", function(e) { | ||
if (myForm.checkValidity()) { | ||
e.preventDefault(); | ||
alert("Form submitted successfully!"); | ||
} | ||
}); | ||
|
||
sw.addEventListener("ui5-change", function(e) { | ||
lbl.innerHTML = e.target.checked + " : " + (++counter); | ||
field.value = counter; | ||
|
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 |
---|---|---|
|
@@ -28,6 +28,8 @@ const Template: UI5StoryArgs<Switch, StoryArgsSlots> = (args) => html`<ui5-switc | |
design="${ifDefined(args.design)}" | ||
?checked="${ifDefined(args.checked)}" | ||
?disabled="${ifDefined(args.disabled)}" | ||
?required="${ifDefined(args.required)}" | ||
?name="${ifDefined(args.name)}" | ||
text-on="${ifDefined(args.textOn)}" | ||
text-off="${ifDefined(args.textOff)}" | ||
accessible-name="${ifDefined(args.accessibleName)}" | ||
|
@@ -60,4 +62,43 @@ export const Design = Template.bind({}); | |
Design.args = { | ||
design: SwitchDesign.Graphical, | ||
accessibleName: "graphical", | ||
}; | ||
}; | ||
|
||
export const RequiredInForm = Template.bind({}); | ||
RequiredInForm.args = { | ||
required: true, | ||
name: "termsAndConditions", | ||
disabled: false, | ||
design: SwitchDesign.Textual, | ||
textOn: "Yes", | ||
textOff: "No", | ||
}; | ||
RequiredInForm.decorators = [ | ||
(story) => { | ||
return html` | ||
<style> | ||
.switch-form { | ||
max-width: fit-content; | ||
border: 1px solid var(--sapList_BorderColor); | ||
border-radius: 0.5rem; | ||
padding: 1rem; | ||
} | ||
</style> | ||
<form id="myForm" class="switch-form"> | ||
<h3 style="margin: 0 0 1rem 0">Switch in Registration form sample</h3> | ||
<div style="display: flex; flex-direction: column;"> | ||
<ui5-input required type="Email" placeholder="Email" value="[email protected]"></ui5-input> | ||
<ui5-input required type="Password" placeholder="Password" value="[email protected]"></ui5-input> | ||
</div> | ||
<div style="display: flex; flex-direction: column; justify-content: center;"> | ||
<ui5-label for="mySwitch" style="margin: 1rem 0 0 0">Please accept the terms and conditions, in order to proceed</ui5-label> | ||
<div style="width: fit-content"> | ||
${story()} | ||
</div> | ||
</div> | ||
<br> | ||
<ui5-button type="Submit">Submit Form</ui5-button> | ||
</form>` | ||
} | ||
]; | ||
|