Uncheck all Checkboxes on a Screen
-
Timo3 years ago #23742
Hi
I search for an usecase to uncheck all checkboxes after backpress the screen.
For input I found these:$(‘:input’).val(”);
It works perfect!
For checkbox these:
$( “input[type=’checkbox’]” ).prop(“checked”, false);
But it does’nt work.
Could someone help me? Thanks a lot.
Jennifer HäfnerHas successfully completed the online course Intermediate (200)Has successfully completed the online course Advanced (300)Has successfully completed the online course Basics (100)Has successfully completed the online course Advanced (310)Has successfully completed the online course Advanced (320)Has successfully completed the Intermediate CertificationHas successfully completed the Advanced Certification3 years ago #24015::Hi Timo,
In OpenUI5, you can uncheck a CheckBox like this:
var oCheckbox = sap.ui.getCore().byId("Screen1--checkbox"); //insert the screen name and the id of your checkbox
oCheckbox.setSelected(false);
If all CheckBoxes that you want to uncheck are wrapped in a container, e.g. Grid or FlexBox, you can first retrieve all CheckBoxes in the container, then uncheck them in a loop:
var oContainer = sap.ui.getCore().byId("Screen1--grid"); //insert your container's id here
var aContainerContent = oContainer.getContent(); //get all controls in the container. if you use a FlexBox, you can retrieve the items by using 'oContainer.getItems()'
aContainerContent.forEach(function(oControl){
if (oControl.getSelected){ //check if the current control has the method 'getSelected'. You don't have to do this if you only have CheckBoxes in your container
oControl.setSelected(false);
}
});
If your CheckBoxes are all on the same page, you can also use this method:
$('#Checkboxes--CheckboxesPage .sapMCb').each(function(){ //insert your page's id in the selector. 'sapMCb' is the UI5 class for CheckBoxes
var oCheckBox = sap.ui.getCore().byId(this.id); //get UI5 object
if (typeof oCheckBox !== 'undefined'){
oCheckBox.setSelected(false);
}
});
I hope this helps!Timo3 years ago #24031::Thank you, it works. 🙂
And I use these for all checkboxes:
$(‘.sapMCb’).each(function(){ //insert your page’s id in the selector. ‘sapMCb’ is the UI5 class for CheckBoxes
var oCheckBox = sap.ui.getCore().byId(this.id); //get UI5 object
if (typeof oCheckBox !== ‘undefined’){
oCheckBox.setSelected(false);
}
});
You must be logged in to reply to this topic.