Skip to Content
0

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

Apr 21, 2017 at 07:11 AM

35

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

VIPLOVE KHUSHALANI Apr 21, 2017 at 07:24 AM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thank you

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

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

Share
10 |10000 characters needed characters left characters exceeded
Sharath M G Aug 17, 2017 at 09:46 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded