cancel
Showing results for 
Search instead for 
Did you mean: 

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

0 Kudos

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.

Accepted Solutions (0)

Answers (3)

Answers (3)

Sharathmg
Active Contributor
0 Kudos

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

former_member340030
Contributor
0 Kudos

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

0 Kudos

Thank you

Former Member
0 Kudos

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