SAPUI5 Get Control associated with Binding - sapui5

I know I can get a binding associated with a control via control.getBinding('example').
Is there anyway to go the opposite way like binding.getControl()?

Not sure if this helps, but take a look at the control property "fieldGroupIds". It's used for validation purposes so you can call all the controls linked to that specific field group. You could use this to identify all the controls using that specific binding and calling all the controls linked to that field group. See documentation below:
Field Groups
Accessing Controls in a Field Group:
In some scenarios, it is required to find all controls that belong to a specific field group, or to all controls with a fieldGroupId. For this, the control implements the public getControlsByFieldGroupId method that gets a list of child controls in the application code.
var aAllControlsWithFieldGroupId = myVerticalLayout.getControlsByFieldGroupId(); //all where fieldGroupId is not empty
var aMyGroupControls = myVerticalLayout.getControlsByFieldGroupId("myGroup"); //exact matches to myGroup
Similar to the above you can use the byFieldGroupId method of sap.ui.Core to all controls with certain field group IDs.
var aAllControlsWithFieldGroupId = sap.ui.getCore().byFieldGroupId(); //all where fieldGroupId is not empty
var aMyGroupControls = sap.ui.getCore().byFieldGroupId("MyGroup"); //exact matches to myGroup
var aNotGrouped = sap.ui.getCore().byFieldGroupId([]); //exact empty array (default value of fieldGroupIds)

Related

SAPUI5 No dynamic way to get form data without data binding. And no Form submit event.

I have a simple form that's in a dialog fragment used to submitting two fields for log-in auth.
For simplicity I was hoping to not have to use data binding, but rather use some method to gather all data inside my sap.ui.layout.form.SimpleForm.
I added a name property to each input element which says in the docs it is " Defines the name of the control for the purposes of form submission."
https://openui5.hana.ondemand.com/#/api/sap.m.InputBase/controlProperties#name
However hard as I try to find there doesn't seem to be any getFormData methods.
All SO questions and guides either use data binding to a model, or hard-code references to the individual input controls with .getValue() methods.
And looking further into the form API, there doesn't seem to be a Submit event either.
Given an arbitrary form, what would be the best way to gather all submission values without hard-coded references or data-binding?
Would a method that walks though all the children elements of a form looking for all submission values work? I think it might, but there are more submission input types then just the input component.
You can get the value of the fields by directly using;
var oField = sap.ui.getCore().byId('IdOfTheFieldAtTheDialog');
var sValue = oField.getValue();
But it's always better and convenient to use data binding which keep things neat.
And If I assume that you have the id of parent form container, you can iterate over the items and get the sap.m.Input elements in it without knowing the IDs of the individual inputs, and you may check the name property of the fields if you want. Check this snippet;
https://jsfiddle.net/hdereli/9e92osfk/3/

How to retrieve the rows which are selected in the list report page of smart templates

This is the List Report type of Smart Template application
Here I have selected 2nd and 5th row, I also have a button named Send Requests in the section part which is highlighted. If I click this button it calls a javascript controller function which is defined in the extensions of the application. In this js function how can I retrieve the selected rows that are selected?
I have enabled the checkboxes in this page by mentioning this code
"settings": { "gridTable": false, "multiSelect": true } in the manifest.json
As it was recommended by this link https://sapui5.netweaver.ondemand.com/#docs/guide/116b5d82e8c545e2a56e1b51b8b0a9bd.html
I want to know how can I retrieve the rows which got selected?
There is an API that you can use for your use case. It is described here: https://sapui5.netweaver.ondemand.com/#docs/guide/bd2994b69ef542998becbc69ab093f7e.html
Basically, you just need to call the getSelectedContexts method. Unfortunately you will not be able to really get the items themselves, only the binding contexts (which point to the data entities which are selected). Excerpt from the documentation:
After you have defined a view extension, you can access and modify the
properties of all UI elements defined within these extensions (for
example, change the visibility). However, you cannot access any UI
elements that are not defined within your view extensions.
In this type of table there is way.
var myTable=sap.ui.getCore().byId("your table id");
get all rows:
var myTableRows=myTable.getRows();
now get selected Indices
var selectedIndeices=myTable.getSelectedIndices(); //this will give you array of indeices.
now run loop on indeices array. And get particular row item;
// get binding path
var bindingpath=myTableRows[2].getBindingContext().sPath; // this will return eg:"/ProductCollection/2"
// now get Binding object of that particular row.
var myData=myTableRows[2].getModel().getObject(bindingpath); // this will return binding object at that perticular row.
// once your loop is over in the end you will have all object of selected row. then do whatever you want to do.
If you use smart template create an extension.
This is the standard event befor the table is rebinding:
onBeforeRebindTableExtension: function (oEvent) {
this._table = oEvent.getSource().getTable();
}
In your action function (or where you want) call the table and get the context :
this._table.getSelectedContexts();

Adding a form filter

I'm currently working on a form in Microsoft Dynamics AX.
The form consists of a grid with about 10 fields from 4 different tables.
As the form is now it returns too many values so I need to include some sort of filter, it doesn't need to be dynamic, just a static filter saying only show the lines with value X in column Y.
Has anyone here got some experience with this sort of thing? Where do I start?
I must say I'm not experienced with Microsof AX at all, I've been working with it for about a month now.
I've tried to follow this guide: How to: Add Filter Controls to a Simple List Form [AX 2012]
But I got stuck at the second part (To add a control to the custom filter group) Step 2: I dont know which type of control to chose, and ik i pick lets say a ComboBox i cant get Step 3 to work because I dont see the 'Override Methods' they mention.
Well, I usually do it this way:
In ClassDeclaration, create as many QueryBuildRanges variables as fields to filter. Let's name them Criteria1, Criteria2, etc (name them properly, please, not as here)
QueryBuildRange criteria1, criteria2;
In each Datasource you need to filter, override method Init, an add code similar to this:
super();
criteria1 = this.query().datasource(tablenum(tableofdatasource)).addQueryRange(fieldNum(fieldtofilter))
//criteria1.status(RangeStatus::locked); //optional - this way you can hide filter field to user, have it readonly for users, etc
Create a control of type StringEdit or ListBox in form to be used as filter. Change their AutoDeclaration property to Yes. Override modified() method. In it, I use to put something similar to:
super();
element.changeFilters();
In form, add method changeFilters();
range rangeFromStringControl = StringEditControlName.text(); //Put in rangeFromStringControl the string to be used as filter, as a user would write it
range rangeFromListBoxControl;
criteria1.value(rangeFromStringControl);
switch (listBoxControl.Selection())
{
case NoYesAll::All:
rangeFromListBoxControl = ''; //Empty filter string - No filter at all
break;
case NoYesAll::No:
rangeFromListBoxControl = QueryValue(NoYes::No); //Or whatever string filter value you want
break;
//Etc
}
//We have all filter strs done; let's filter for each main DataSource required with new filters
DataSource1.executeQuery();
//If there is other datasources joined to this one, it's usually no necessary to call their executeQuery;
//If there are others with filters and not joined to it, call their executeQuery()
If you need this filter to be applied when form is open, set appropiate initial values to controls, and then in form's run() method:
run();
element.changeFilters();

How to sort a pi_list_query (or pi_exec_query) listing

I am using the extension feuserlisting to present my visitors a list of site members, but I'd like to sort the list on the full name. I know I can click the table heading to sort it when it is presented on the screen, but somehow it should be possible to set the default sorting by TypoScript?
The way of doing it is to use the _DEFAULT_PI_VARS mechanism.
plugin.tx_feuserlisting_pi1._DEFAULT_PI_VARS {
sort = name:0
}
The list view method of feuserlisting initilizes with a call to $this->pi_setPiVarDefaults() (which is inherited from tslib_pibase), where the key _DEFAULT_PI_VARS is taken into account when establishing the piVars.
This technique should be available in all pibase extensions which initialize their piVars with such a call.

Dynamic list of checkboxes

I have a list of AccessPrivileges and I would need to create a form with a dynamic list of checkboxes, however I cannot find a solution inside the documentation.
Assuming you have the following
class AccessPrivilege(dataType:String, description:String)
object AccessPrivilege {
val privileges:Seq[AccessPrivilege] = ....
}
I would need to generate a binding so that , in my form I can:
Have a checkbox whose label is the description
Being able to retrieve the list of selected checkboxes as a List of String and not as a List of boolean.
I can't find among the form helpers what I need, because the checked returns a boolean, while I need to "collect" the selected checkboxes...