Skip to Content
0

SAPUI5: Object Page with blocks

Jan 26, 2017 at 08:26 AM

242

avatar image

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", {
     });
});
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

VIPLOVE KHUSHALANI Jan 27, 2017 at 09:24 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded