Simplifier Community Home Forums Simplifier Forum Uncheck all Checkboxes on a Screen

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #23742
    AvatarTimo
    Participant
    • Topics: 3
    • Replies: 3
    • Padawan

    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.

     

    #24015
    AvatarJennifer
    Participant
    • Topics: 0
    • Replies: 4
    • Padawan
    Up
    1
    Down

    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!

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.