Issues in store-fed dijit/form/Select by setting preselected value in dojo 1.8 - select

There is another issue when I try to set the preselected (or any) value of my store-fed dijit/form/Select widget.
The markup code is:
<div data-dojo-type="dijit/form/Select" jsId="editOptionsDialog_select" id="editOptionsDialog_select"></div>
and the js:
function editOptionsDialog_fetchData(cId, fieldName, vId) {
var store;
var def;
var return_def = new Deferred();
store = new degreeStore();
def = store.getJsonData();
def.then(function(data) {
store.data = data.items;
editOptionsDialog_select.setStore(new ObjectStore({
objectStore : store
}));
editOptionsDialog_select.value = vId;
editOptionsDialog_select.startup();
editOptionsDialog_select.set('value', 5);
console.info(editOptionsDialog_select);
// here, firebug still shows value = 1
return_def.resolve();
});
return return_def;
}
thx in advance
Greetings

Finally found a solution to the problem:
Since the selection-element DOES NOT support numerical indexes, the indexes had to be casted to strings. With that, a editOptionsDialog_select.set('value', vId.toString()) has finally worked!
Be sure to feed your store by casted numerical ids or then textual-keys by default -> (String)id where id is an integer.
Greetings

Related

get value for specific question/item in a Google Form using Google App Script in an on submit event

I have figured out how to run a Google App Script project/function on a form submit using the information at https://developers.google.com/apps-script/guides/triggers/events#form-submit_4.
Once I have e I can call e.response to get a FormResponse object and then call getItemResponses() to get an array of all of the responses.
Without iterating through the array and checking each one, is there a way to find the ItemResponse for a specific question?
I see getResponseForItem(item) but it looks like I have to somehow create an Item first?
Can I some how use e.source to get the Form object and then find the Item by question, without iterating through all of them, so I could get the Item object I can use with getResponseForItem(item)?
This is the code I use to pull the current set of answers into a object, so the most current response for the question Your Name becomes form.yourName which I found to be the easiest way to find responses by question:
function objectifyForm() {
//Makes the form info into an object
var myform = FormApp.getActiveForm();
var formResponses = myform.getResponses()
var currentResponse = formResponses[formResponses.length-1];
var responseArray = currentResponse.getItemResponses()
var form = {};
form.user = currentResponse.getRespondentEmail(); //requires collect email addresses to be turned on or is undefined.
form.timestamp = currentResponse.getTimestamp();
form.formName = myform.getTitle();
for (var i = 0; i < responseArray.length; i++){
var response = responseArray[i].getResponse();
var item = responseArray[i].getItem().getTitle();
var item = camelize(item);
form[item] = response;
}
return form;
}
function camelize(str) {
str = str.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()#\+\?><\[\]\+]/g, '')
return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match, index) {
if (+match === 0) return ""; // or if (/\s+/.test(match)) for white spaces
return index == 0 ? match.toLowerCase() : match.toUpperCase();
});
}
//Use with installable trigger
function onSubmittedForm() {
var form = objectifyForm();
Logger.log(form);
//Put Code here
}
A couple of important things.
If you change the question on the form, you will need to update your
code
Non required questions may or may not have answers, so check if answer exists before you use it
I only use installable triggers, so I know it works with those. Not sure about with simple triggers
You can see the form object by opening the logs, which is useful for finding the object names

Value of text field in protractor- undefined

I am not able to get value of label (as value is not editable and return by API).
I am using getText, but out put is always undefined. The value of this field is 2222.
using below
var activatedid = element(By.xpath("/html/body/app-root/mat-toolbar/div[3]/div[3]"));
activatedid.getText()
.then(function(text) {
console.log(this.text);
Remove this. before text, so you have
var activatedid = element(By.xpath("/html/body/app-root/mat-toolbar/div[3]/div[3]"));
activatedid.getText()
.then(function(text) {
console.log(text);
})

Convert Document element to Protractor element

Is it possible to convert my jquery element to protractor element? For example:
browser.executeScript(() => {
var ele = $(".datatable-row-wrapper .hdt-d:not('not-active')").get(0);
return ele;
}).then(ele => {
**//// this throwing error**
element(ele).click();
});
One option would be to instantiate an ElementFinder instance (not tested):
var elementLib = require('protractor/built/element');
var ElementFinder = elementLib.ElementFinder;
var elementFinder = ElementFinder.fromWebElement_(browser, ele, by.css(".datatable-row-wrapper .hdt-d:not('not-active')"));
elementFinder.click();
Even though I've never encountered the need to actually do so.
The other way around - passing an ElementFinder into a script is much easier:
var elm = $(".datatable-row-wrapper .hdt-d:not('not-active')");
browser.executeScript("arguments[0].click();", elm.getWebElement());

jsTree customize <li> using the alternative JSON format along with AJAX

I am using the alternative JSON format along with AJAX to load data in tree. Now there is a new ask, I am required to add a new element at the end of <li> tag.
I have created sample URL to display what I am currently doing.
Tree crated using alternative JSON format along with AJAX
And how the new LI should appear
Tree created using hard coded HTML but shows how the LI should look like
I think I should be able to do this if I use HTML Data but since the project is already live with JSON format this would require me to change a lot so before I start making this major change I just wanted to check if this is possible using JSON and AJAX format or not.
So I got answer from Ivan - Answer
In short there is misc.js in the src folder which has question mark plugin, this is the best example of what I wanted to do.
I tweaked its code for my needs and here is the new code.
(function ($, undefined) {
"use strict";
var span = document.createElement('span');
span.className = 'glyphicons glyphicons-comments flip jstree-comment'
$.jstree.defaults.commenticon = $.noop;
$.jstree.plugins.commenticon = function (options, parent) {
this.bind = function () {
parent.bind.call(this);
};
this.teardown = function () {
if (this.settings.commenticon) {
this.element.find(".jstree-comment").remove();
}
parent.teardown.call(this);
};
this.redraw_node = function (obj, deep, callback, force_draw) {
var addCommentIcon = true;
var data = this.get_node(obj).data;
//....Code for deciding whether comment icon is needed or not based on "data"
var li = parent.redraw_node.call(this, obj, deep, callback, force_draw);
if (li && addCommentIcon) {
var tmp = span.cloneNode(true);
tmp.id = li.id + "_commenticon";
var $a = $("a", li);
$a.append(tmp);
}
return li;
};
};
})(jQuery);

dojo.data.ItemFileReadStore: Invalid item argument. while reloading data

I am facing a strange problem here. I have a Select box displaying Department field value. Onchange of the department option, I have to populate the grid. When the page loads first time, the onChange event works fine and the data gets loaded perfectly in the grid. When I change the Department in the Select box, I get error in firebug "dojo.data.ItemFileReadStore: Invalid item argument".
I checked the JSON returned from server and it is exactly same as the JSON loaded earlier. Here are the code snippet of my code
HTML
<div id="costCenter" data-dojo-type="dijit/form/Select" data-dojo-attach-point="costCenter" data-dojo-attach-event="onChange:loadStacks"></div>
JS
loadStacks: function() {
var requestParams = {};
requestParams.Action = "getStacks";
requestParams.callType = "ajaxCall";
requestParams.deptID = deptID;
var docData = null;
request.invokePluginService("MyPlugin", "UtilityService",
{
requestParams: requestParams,
requestCompleteCallback: lang.hitch(this, function(response) { // success
docData= response.Data;
var dataStore = new dojo.data.ItemFileReadStore({data: docData});
grid = dijit.byId("docGrid");
grid.attr('structure', docStructure);
grid.attr('store', dataStore);
grid.render();
})
}
);
}
JSON data returned:
docData : {"items":[{"docName":"test3","id":135,"order":1},{"docName":"Ashish","id":4085,"order":21},{"docName":"fsdfsadf","id":4088,"order":23}],"identifier":"docName"}
Any idea about it?
Solved it myself. Added below lines before setting new store to the grid.
if (null != grid.store)
{
grid.store.close();
grid.store.fetch({query: {docName: "*"}});
grid._refresh();
}
And set clearOnClose: true while setting new store.