Skip to Content

how can I get the value from the form which is written in controller?

In controller i have written a simple form. on click of a button this form will appear. I want to know how to take its value if i enter some data in the field without using id.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Apr 21, 2017 at 07:24 AM

    Hi RAHEEN AFSHAN,

    You need to use model for this to get any controls property value ..

    If you don't want to use the id of the form than attach the model with a model name to the view or page which contains your simple form

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

    model.setData({SupplierName:'',HouseNumber:'',Street:'',ZIPCode:'',City:'',Country:''});

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

    this.getView().bindElement("formModel>/");

    1. <f:SimpleForm
    2. minWidth="1024"
    3. maxContainerCols="2"
    4. editable="false"
    5. layout="ResponsiveGridLayout"
    6. title="Address"
    7. labelSpanL="3"
    8. labelSpanM="3"
    9. emptySpanL="4"
    10. emptySpanM="4"
    11. columnsL="1"
    12. columnsM="1">
    13. <f:content>
    14. <Label text="Name"/>
    15. <Input value="{formModel>SupplierName}"/>
    16. <Label text="Street/No."/>
    17. <Input value="{formModel>Street} {formModel>HouseNumber}"/>
    18. <Label text="ZIP Code/City"/>
    19. <Input value="{formModel>ZIPCode} {formModel>City}"/>
    20. <Label text="Country"/>
    21. <Input value="{formModel>Country}"/>
    22. </f:content>
    23. </f:SimpleForm>

    Now on Button press event you can get the data of the model attached

    onPress:function(){

    var data = this.getView().getModel("formModel").getData() // data contains the values you enter in the input fields above

    }

    thanks

    Viplove

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 21, 2017 at 07:18 AM

    Instead of getting values by element ID's we can get through model.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 17, 2017 at 09:46 AM

    Any data from view to controller can be linked using data models. On binding, data typed on view will be instantly available in the models, which are accessible in controller.

    Element iD is also another way to get the data entered by user in view.

    SAP recommends usage of model binding to transfer data between views and controller.

    Regards,

    Sharath

    Add comment
    10|10000 characters needed characters exceeded