cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5: Object Page with blocks

alpi
Explorer
0 Kudos

I've got this ObjectPageLayout:

request.view.xml

<ObjectPageLayout>
  <headerTitle>
  ...
  </headerTitle>
  <headerContent>
  ...
  </headerContent>
  <sections>
    <ObjectPageSection mode="Collapsed">
      <subSections>
        <ObjectPageSubSection title="fooBlock">
          <blocks>
            <blockdetail:FormBlock columnLayout="auto" /> <!-- MY BLOCK -->
          </blocks>
        </ObjectPageSubSection>
      </subSections>
    </ObjectPageSection>
  </sections>
</ObjectPageLayout>

FormBlockCollapsed.view.xml (MY BLOCK)

<mvc:View xmlns:f="sap.ui.layout.form" xmlns:mvc="sap.ui.core.mvc"
    xmlns:core="sap.ui.core" xmlns:l="sap.ui.layout" xmlns="sap.m"
    controllerName="NAMESPACE.blocks.DetailsBlockCommon">
 <FlexBox>
  <HBox>
   <VBox>
    <f:SimpleForm >
     <f:content>
       <CheckBox id="myCheckbox" />
     </f:content>
    </f:SimpleForm>
   </VBox>
  </HBox>
 </FlexBox>
    ...
</mvc:View>

So far, everything is fine. My Object page looks good a the checkbox is shown. In my Controller request.controller.js i want to validate the checkbox in FormBlockCollapsed.view.xml

validateBlockForm: function(format){
   console.log( oView.byId("myCheckbox").checked() ); //oView.byId("myCheckbox") is undefined
}

But i've no access to my checkbox in the block.

Cannot read property 'checked' of undefined

Additional infos

----------------------------------------

FormBlock.js

sap.ui.define(['sap/uxap/BlockBase'], function (BlockBase) {
    "use strict";
      var MultiViewBlock = BlockBase.extend("NAMESPACE.blocks.FormBlock", {
        metadata: {
         views: {
           Collapsed: {
               viewName: "NAMESPACE.blocks.FormBlockCollapsed",
               type: "XML"
           }
         }
      }
    });
    return MultiViewBlock;
}, true);

DetailBlockCommon.js

sap.ui.define([
    "NAMESPACE/controller/BaseController"
    ], function (BaseController) {
    "use strict";
      return BaseController.extend("NAMESPACE.blocks.DetailsBlockCommon", {
     });
});

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member340030
Contributor
0 Kudos

Hi Alex,

Use models to check validate the check box

<CheckBox selected = "{validate>value}"/> // don't require id if we use model and it better to use models everywhere

onInit : function(){

var val = {value:true} // inital value

var model = new sap.ui.model.json.JSONModel();

model.setData({Set : val});

this.getView().setModel(model,"validate");

this.getView().bindElement("validate>/Set");

}

Now in validation method you can check the value :

validateBlockForm:function(){

var val = this.getView().getBindingContext("validate").getProperty();

var check = val.value; //check will have the selected value of check box

}

thanks

Viplove