SAPUI5 selection change event issue in multi select list - sapui5

I've a popover component and I added a multi-select list inside of it. I would like to set checked property to true for all items in case of the first item of list is selected. But selectionChange event works for every item's selection event. So, index value of the for loop always starts with zero. What should I do in this situation? Thanks for your suggestions.
Here is my part of a code and screenshot of image;
image url
new sap.m.List('statusTypesList', {
mode: 'MultiSelect',
selectedKeys: " ,1,2,3",
includeItemInSelection: true,
selectionChange: function(oEvent) {
var keyValues = "";
var itemArray = oEvent.oSource.getItems();
if(itemArray[0].getSelected()==true){
for (var i = 0; i < itemArray.length; i++) {
oEvent.oSource.setSelectedItem(itemArray[i], true, true);
}
}
}
})

Check if the item that fired the event is the first one in your list. Something like this:
function(oEvent) {
var changedItem = oEvent.getParameter('listItem');
if(changedItem isTheFirstItem){
//Where 'isTheFirstItem' is the condition you define to identify your first item
var keyValues = "";
var itemArray = oEvent.getSource().getItems();
if(itemArray[0].getSelected()==true){
for (var i = 0; i < itemArray.length; i++) {
oEvent.getSource().setSelectedItem(itemArray[i], true, true);
}
}
}
Define the condition you want in the if(changedItem isTheFirstItem) statement
Try this condition, maybe it works: if(changedItem === oEvent.getSource().getItems()[0])
If not, just build your own condition to check if it is the first one or not
NOTE: User getSource() to get the source from the event. It is always better than accessing the object directly

Related

How to add and edit a short answer in multiple google forms

So I have multiple google forms (around 20 forms), that I need to do 2 things to them:
1- These 20 forms are placed in a folder in my google drive. I need to add more like an "Access code" where users will have to insert in order to continue the solving the quiz.
The way I did that was to add a "short answer" question to "section 1" of the quiz asking "Enter your Access Code", add "response validation", "Regular expression" and "Pattern". Also making this a "required question". This should look something like the below picture
Example of google form
So is it possible to have a scriptto add this question to all 20 forms
2- The "access code" in these google forms will have to be updated frequently, so I don' want to be updating the "Pattern" manually for each form, is t possible to have a google script to edit the value of the pattern for each form
Thanks in advance guys :)
I managed to solve this issue that I was having, through looking for different codes and here are the codes that I used.
N.B. The codes might not be very clean as I was copying them from other parts/projects, but they have worked for me
1- Update the 20 forms with adding the access code question, I figured it was not possible to add a question at a certain position in the google form, however I can add a question at the end of the form and then move this item to the position I want:
function AddAccesscodeQ() {
var filess = DriveApp.getFolderById("Drive id>").getFiles();
while (filess.hasNext()) {
var file = filess.next();
var form = FormApp.openById(file.getId());
var sectionIndex= 0; // Please set the index you want to insert.
//I added a "sample item" to be moved and edited later
var newItemQ = form.addTextItem().setTitle("New sample item").getIndex(); // New sample item
// I added a Pagebreak that also should be moved after the questions "Enter Your Access Code"
var newItemPB = form.addPageBreakItem().getIndex();
var items = form.getItems(FormApp.ItemType.PAGE_BREAK);
var sections = [0];
for (var i = 0; i < items.length; i++) {
// I pushed the items in the google form twice downwards, to be able to move the "sample item" and "Page break" to the top of the form
sections.push(items[i].getIndex());
sections.push(items[i].getIndex());
}
var insertIndex = sections[sectionIndex + 1] || null;
if (insertIndex) {
// Here I moved the 2 new items to the desired positions
form.moveItem(newItemQ, 0);
form.moveItem(newItemPB, 1);
}
// Here I am going to edit the "Sample Question" to be as desired
var itemss = form.getItems();
var itemID = itemss[0].getId();
var itemse = form.getItemById(itemID).asTextItem()
.setTitle('Enter Your Access Code').setRequired(true);
//Create validation rule
var validation = FormApp.createTextValidation()
.setHelpText('Invalid Code')
.requireTextMatchesPattern("<Access Code>")
.build();
itemse.setValidation(validation);
}
}
2- The second problem was that I later might need to change this access code to a new one for the 20 forms
function UpdateAccessCode() {
var filesPhCH = DriveApp.getFolderById("<Drive ID>").getFiles();
while (filesPhCH.hasNext()) {
var file = filesPhCH.next();
var form = FormApp.openById(file.getId());
var items = form.getItems();
//Loop through the items and list them
for (var i = 0;i<items.length;i++){
var item = items[i];
var itemID = item.getId();
var itemtitle = item.getTitle();
var itemindex = item.getIndex();
// I found no need to continue the for loop since the items that need modification are at the top of the form
if (itemindex == 0){
break;
}
}
//Select the question you want to update
var itemse = form.getItemById(itemID).asTextItem()
.setTitle('Enter Your Access Code');
//Create validation rule
var validation = FormApp.createTextValidation()
//.setTitle('Enter Your Access Code');
.setHelpText('Invalid Code')
.requireTextMatchesPattern("<Enter the new Access Code>")
.build();
itemse.setValidation(validation);
}
}
I hope this might help someone as it has saved a lot of time for me ;)

how to get button click with dynamic parameter in unity 2d version 2019.3.7

I have below structure, I need to parse every ID on button click, Insort I need ID to another screen. Anyone please help me to do this.
SCREEN 1 :
expected SCREEN 2 :
Welcome to ID : [DYNAMIC ID from Last PLAY btn click]
Software/platform I am working on
Unity 2D Version 2019.3.7f*, Data come from MongoDB Json
foreach (var document in playercollection.Find(where14))
{
var dotNetObj = BsonTypeMapper.MapToDotNetValue(document);
var jsonstring = JsonConvert.SerializeObject(dotNetObj);
TableClass myObject = JsonUtility.FromJson<TableClass>(jsonstring);
table_data.text = myObject.table_name;
table_boot.text = myObject.boot;
table_pot.text = myObject.pot_limit;
GameObject newitems = Instantiate<GameObject> (itemPrefab, transform);
}
You can add onclick listener dynamically and pass the id. Assuming you are adding this UI rows dynamically if yes then you can do the following:
button.onClick.AddListener(() => ButtonClicked("my_id"));//write this in the loop or where you are generating UI rows.
void ButtonClicked(string id)
{
Debug.Log("Button clicked = " + id);
}
Based on your edited question and assumption itemPrefab has a Button component attached following should work.
foreach (var document in playercollection.Find(where14))
{
var dotNetObj = BsonTypeMapper.MapToDotNetValue(document);
var jsonstring = JsonConvert.SerializeObject(dotNetObj);
TableClass myObject = JsonUtility.FromJson<TableClass>(jsonstring);
table_data.text = myObject.table_name;
table_boot.text = myObject.boot;
table_pot.text = myObject.pot_limit;
GameObject newitems = Instantiate<GameObject> (itemPrefab, transform);
newItems.GetComponent<Button>().AddListener(() => ButtonClicked("my_id"));//use id from the document
}

Default Selected list item in Master view of the SplitApp

I have one SplitApp with Master -Detail layout. I would like to know how can I set the first item in Master view to default so that on loading of application Detail view shows the information about the select list item. So when user open the application automatically first item in Master should be selected and Detail View show the information.
I am using Objectlist Item as control for Master view. And currently using the select event for selecting the list item.
var oList = new sap.m.List("idMasterList",{
mode: sap.m.ListMode.SingleSelect,
select: [oController.onSelectItem, oController]
});
onSelectItem: function(oEvent){
//var app = sap.ui.getCore().byId("splitApp");
var oMasterList = sap.ui.getCore().byId("idMasterList");
var oSelItem = oMasterList.getSelectedItem();
var sPath = oSelItem.oBindingContexts.druginfo.sPath;
var oItem = sap.ui.getCore().getModel("druginfo").getProperty(sPath);
var oSelModel = new sap.ui.model.json.JSONModel(oItem) ;
sap.ui.getCore().setModel(oSelModel, "SelectedItem");
}
Regards,
Mayank
It seems like there is (hidden) API to make the select event fire when setting the selected item:
ListBase.prototype.setSelectedItem = function(oListItem, bSelect, bFireEvent) {
if (this.indexOfItem(oListItem) < 0) {
jQuery.sap.log.warning("setSelectedItem is called without valid ListItem parameter on " + this);
return;
}
if (this._bSelectionMode) {
oListItem.setSelected((bSelect === undefined) ? true : !!bSelect);
bFireEvent && this._fireSelectionChangeEvent([oListItem]);
}
};
You could use setSelectedItem once your lists data is loaded (e.g. change event of aggregation binding items) like this:
var oList = this.getView().byId("MyListID"),
oFirstItem = oList.getItems()[0];
oList.setSelectedItem(oFirstItem, true, true);
This will trigger the selectionChange resp. select event and your already existing event listener will be triggered.

Update OpenLayers popup

I am trying to update some popups in my map but I am not able to do that.
Firstly I create some markers, and with the next code, I create a popup associated to them. One popup for each marker:
popFeature = new OpenLayers.Feature(markers, location);
popFeature.closeBox = true;
popFeature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
'autoSize': true
});
popFeature.data.popupContentHTML = "hello";
popFeature.data.overflow = (false) ? "auto" : "hidden";
var markerClick = function (evt) {
if (this.popup == null) {
this.popup = this.createPopup(this.closeBox);
map.addPopup(this.popup);
this.popup.show();
} else {
this.popup.toggle();
}
currentPopup = this.popup;
OpenLayers.Event.stop(evt);
};
mark.events.register("mousedown", popFeature, markerClick);
After that, I add the new marker to my marker layer.
Everything is fine until here, but, I want to update the popupcontentHTML some time later and I don't know how I can access to that value.
I read OL API but I don't understand how to get it. I am lost about features, events, extensions...
I want to know if I can access to that property and write other word.
I answer myself, maybe it helps other people in future:
for(i = 0; i < map.popups.length; i++){
if(map.popups[i].lonlat.lon == marker.lonlat.lon){
map.popups[i].setContentHTML("new content");
}
}
Content will be refreshed at the moment.

Add ondblClick and click event to Codemirror

I would like to add onDblClick event to codemirror 2. I found that onCursorActivity does not deliverer the event so there is no way for me from this method to filter the events.
How can I implement onDbClick event on Codemirror ?
Thanks in advance.
You can call on method on object returned by CodeMirror:
var cm = CodeMirror.fromTextArea(document.querySelector('textarea'));
cm.on('dblclick', function() {
alert('You double click the editor');
});
You can find the list of all available events in documentation.
Register a handler on the element returned by the getWrapperElement() method. Unless you want to not just detect double-clicks, but also prevent the default (select word under mouse cursor) from occurring... in that case I guess some modification of the core code is needed.
http://jsfiddle.net/yusafkhaliq/NZF53/1/
Since codemirror renders inside the element specified you can add an ondblclick event to the element, like below the highlighter renders without line numbers once double clicked that specific elements will display line numbers
var codeelems = document.getElementsByClassName("code");
for (i = 0; i < codeelems.length; i++) {
(function ($this) {
var value = $this.innerHTML;
$this.innerHTML = "";
var editor = CodeMirror($this, {
value: value,
mode: "text/javascript",
lineNumbers: false
});
$this.ondblclick = function () {
editor.setOption("lineNumbers", true);
}
})(codeelems[i]);
}