Filtering SelectDialog entries - problem with setting value on Close event - sapui5

I have a problem with setting a value to an Input field after filtering the SelectDialog entries in SAP UI5.
Items from SelectDialog list are bound to the named JSON model:
items="{ValueHelp>/MATGRP/results}"
Filtering is perfomed on the "search" event like so:
var sValue = oEvent.getParameter("value");
var oFilter = new Filter({
filters: [
new Filter("DESCRIPTION", FilterOperator.Contains, sValue),
new Filter("CODE", FilterOperator.Contains, sValue)
],
and: false
});
oEvent.getSource().getBinding("items").filter(oFilter);
While filtering works nicely and the List is getting refreshed - selecting a value and performing a setSelectedKey on an Input field - doesn't set any value to it. I'm setting the value like so:
this.sInput.setSelectedKey(oEvent.getParameter("selectedItem").getDescription());
If I do not use the search functionality and select the value from the list right away - the Input field gets the value populated after the Dialog is closed.
Do you have any ideas on what I might be missing?

The issue has been resolved. This problem appeared due to the fact that I am also using "suggestionItems" aggregation and it is limited to 100 records by default. So logically an item that was found in the SuggestDialog - was not present in the suggestionItems aggregation.
I have implemented "suggest" callback for my Input control and now suggestionItems get filtered out just fine and selected item from the Suggest Dialog gets populated correctly.
This question provides a solution.

Related

When programatically setting a set type filter, the floating filter box isn't updated

When I use the selectvalue API to programatically control a set based filter, the floating filter window doesn't update.
If you select and deselect from the floating filter window manually it works fine.
See https://plnkr.co/edit/707g7FHCPOOi26AlUpyn?p=preview
Click on the API: Filter only John Joe Nevin and Kenny Egan and it will filter correctly but the floating filter box for Athlete is empty.
If you open the funnel next to it the filter is correct. Unselect something and select something else and the athletes name comes up correctly in the floating filter input box.
Am I missing something?
//Code used to perform the filter.
var athleteFilterComponent = this.gridApi.getFilterInstance("athlete");
athleteFilterComponent.selectNothing();
athleteFilterComponent.selectValue("John Joe Nevin");
athleteFilterComponent.selectValue("Kenny Egan");
this.gridApi.onFilterChanged();
//Turn this option on as well.
floatingFilter='true'
This could be a bug in ag-grid.
However the workaround is to use setModel() api . Something like this worked -
selectJohnAndKenny() {
var athleteFilterComponent = this.gridApi.getFilterInstance("athlete");
athleteFilterComponent.selectNothing();
var model = ["John Joe Nevin", "Kenny Egan"];
athleteFilterComponent.setModel(model);
this.gridApi.onFilterChanged();
}

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();

Angular 2 - Dynamic Reactive form with Radio Inputs build with FormBuilder, FormGroup, FormArray

Case:
I have an array of answers which I want to show in the view as radio inputs. When one of the answers is already answered it must be [checked] and if it's [checked] a textarea shows, so far so good.
Next I want to check another radio input and I want the current selected to be deselected and its textarea hidden, then the new selected radio input should be [checked] and it's textarea should show.
I use the FormBuilder and FormArray and have following issues.
I can't use index without intrapolation, I see many examples where the index is used without.
If I select another radio input, first my data disappears and it's not checked and on the second click it get's checked but now both are checked.
- I don't have access to the checked event, I can show it in the view with {{tempVar.checked}} as you can see above, if I use a template variable #tempVar, but I don't have access to it in the textarea below *ngIf="tempVar.checked". If I do use it in the ngIf I get the following error
Expression has changed after it was checked. Previous value: 'false'. Current value: 'true'.
Questions:
Is this the right approach?
An example of a Reactive Dynamic form with FormBuilder and FormArray with Radio inputs
Here is my code
https://gist.github.com/webwizart/121c85a0f316f47977cc0c99455af7bf
I would think using the tags should be reserved for unique identifiers? I wouldn't be surprised if dom renderer will update all elements with the same id.
Not sure if this will help, but you could use an answer view model instead (containing the same data) but that also has a 'checked' property
This way you can be sure that it will behave as you would expect.
e.g.: (in your component.ts)
let answers = this.question.Question.PossibleAnswers
.map(a =>
{ return Object.assign({}, a, { checked: false });
}
);
then in html you use: 'answer.checked' instead of 'radio.checked'
ps: also you could use ng-container instead of span, so you don't have an extra DOM imprint in your html

sap.m.Select: start with a blank selection input element

When using a data aggregation on sap.m.Select, the first entry is always selected. Here's a link to the SDK's preview.
Example code from my app
new sap.m.Select("id-names", {
width: '100%',
}).bindAggregation("items", "data>/trip/names", new sap.ui.core.Item({
text: "{data>Name}"
}));
There is a parameter called selectedKey on the constructor to change this to another index. What I want is the select to be blank, because I want to force my users to make a choice, not blandly accept the first entry in the list.
I could force an blank entry in my aggregation data>/trip/names but that would pollute my list.
Is there a better way to achieve this?
Since the OpenUI5 version 1.34, you can set the forceSelection property to false.
The forceSelection property indicates whether the selection is restricted to one of the items in the list. The default value is true (which means, if the selection is not set, the first item in the dropdown list is selected).
When to set it to false?
If you do not want a default item to be pre selected.
Additional information
https://github.com/SAP/openui5/commit/b2191fd50e2115f8f9d2db7604a75fb50c57591f
Currently, no. There seems to be no better way.
There is a ticket for that on GitHub.
It's also my opinion to avoid messing with the dataset and much liked the idea of adding an additional item aggregate. However my improvement on this is to use a formatter on the control itself so it is clearly visible and executed at the right time.
I make use of a formatter with fully qualified controller to get the control as 'this' parameter. In the formatter function I add a ListItem, as proposed by #Victor S
In XML view
<Select forceSelection="false" selectedKey="{model>/key}" items="{path: 'model>/Items'}" icon="{path: '', formatter: 'mynamespace.Utils.addDeselectOption'}">
In the Utils controller:
addDeselectOption: function() {
var that = this;
this.getBinding("items").attachDataReceived(function(){
that.insertItem(new sap.ui.core.ListItem({text: '', key: undefined}), 0);
});
}
Works form me in UI5 1.52
Even though this solution is not great, I managed to get the empty field stick by adding both, the forceSelection=false property, and also in the controller's onInit function (I used the Select element):
var codeField = this.getView().byId("codeField");
setTimeout(function() {
codeField.insertItem(new sap.ui.core.ListItem({text: '', key: undefined}), 0);
}, 1000);
If the forceSelection=false is left out, the field will load either too early or too late to the drop down, which will cause the wrong selection to be visible. Hope it helps someone.
You can also extend the control and build you own select with e.g. an additional parameter add empty choice...I am actually also thinking about that...

ACCESS: Ticking checkbox on form if a value beginning with "(REF)" is selected from combobox

I am trying to tick a check box on a form when I select one of many combobox values that begins with (REF) - this is code that stands for Referral closure.
this is what I've done..it's not working
Private Sub ReasonForInappriopriateReferral_AfterUpdate()
If Me.RsnForInappropriateRef.Value Like "(REF)*" Then
Me.Check66 = True
End If
End Sub
Please help, I was previously trying to conditional format a label to a different colour if the closure reason was a Referral closure, but couldn't do that either and think it could be down to the IF Like command.
I added two controls exactly as you indicated. I populated my combo by setting the Row Source Type to a Value List, and the Row Source to "Blah Blah";"(REF) - Jackson";"Two Times";"(REF) - Tyson"
I put this in the Click event of a button:
If Me.RsnForInappropriateRef.Value Like "(REF)*" Then
Me.Check66 = True
Else
Me.Check66 = False
End If
it behaved exactly as expected. I then moved it to the AfterUpdate event of the combobox, and again it worked flawlessly. The only thing I can see is that in your example, the combobox does not have the same name as your sub (ReasonForInappriopriateReferral vs RsnForInappropriateRef). Are you sure your names are right?