Showing results for 
Search instead for 
Did you mean: 

Reset Button for form Container with different controls

0 Kudos

Hi, I have a form container with a lot of different controls, like ComboBoxes, RadioButtons, CheckBoxes and TextAreas. I want to have a button for reseting all the controls in the form. I am able to reset each control separately like this:

resetPanel: function(){  
this.byId("ComboBox").setSelectedKey(); }

But there are too many controls for doing it to each one separately. Is there any way to do it in the whole form?

I tried this:

var panel = sap.ui.getCore().byId("Form1");

but I get the error that panel is Undefined.
Does anyone have any idea?


Accepted Solutions (0)

Answers (1)

Answers (1)

Active Contributor
0 Kudos

Something that you can do (this is the first thing that came to my mind) is this:

  1. Get the reference to the form
  2. Iterate through all the controls inside the form content
  3. Check if the selected content is from the type of an Input. You can do this step like this -> oControl.getMetadata().getElementName() === sap.m.Input.getMetadata().getElementName()
  4. Create a switch case based on the type of the input. If it's an Input type you can do control.setValue(), it's it's a ComboBox do control.setSelectedKey() and so on and so on.

And all the magic is done!

0 Kudos

Hi, thank you very much for your answer. I am trying to follow this procedure, but I wasn't able to find a way to run through all the controls of the form.Could you give me an example with that?

And also, you suggest to create a case depending on each type of control. But in my form I have for example more than one comboboxes. So, the only way is to give the selectedKey to each combobox by hand? Thank you very much!

Active Contributor
0 Kudos

A good way to do that (sorry but I'm not able to build a live example at the moment) is to put a breakpoint on your JS code and find a way to get all those controls.

If you're using a SimpleForm just look at the documentation. You should be able to loop through it's content doing oForm.getContent()