jqgrid Error : Object does not support Property or Method 'Split' - forms

I am using JQGrid v4.4.1 and MVC3.
When Selecting the 'Next Record' or 'Previous Record' icon on The JQGrid Edit Form, I get a Microsoft JScript runtime error: Object doesn't support property of method 'split'.
If highlights a block of code in the jquery.jqgrid.min.js module : var j=g.split(",")
Sometimes intellesense says that g=0, other times it's -2: I guess it's data related, but i cannot see anything that could be causing this!
I've tried to include a section of this module, including this call, but I'm struggling to make head nor tailof it!
Can anyone help me in determining the cause of this error?
jquery.jqGrid.min.js Extract
2*k+"'>"+t.rowcontent+"</td></tr>"),a(h).append(r),r[0].rp=u);0===m.length&&(m=a("<tr "+q+" rowpos='"+u+"'></tr>").addClass("FormData").attr("id","tr_"+f),a(m).append(p),a(h).append(m),m[0].rp=u);a("td:eq("+(y-2)+")",m[0]).html("undefined"===typeof t.label?e.p.colNames[o]:t.label);a("td:eq("+(y-1)+")",m[0]).append(t.elmprefix).append(l).append(t.elmsuffix);n[j]=o;j++}});if(0<j&&(o=a("<tr class='FormData' style='display:none'><td class='CaptionTD'></td><td colspan='"+(2*k-1)+"' class='DataTD'><input class='FormElement' id='id_g' type='text' name='"+
e.p.id+"_id' value='"+d+"'/></td></tr>"),o[0].rp=j+999,a(h).append(o),c[b.p.id].checkOnSubmit||c[b.p.id].checkOnUpdate))c[b.p.id]._savedData[e.p.id+"_id"]=d;return n}function r(d,e,h){var f,k=0,g,m,j,q,l;if(c[b.p.id].checkOnSubmit||c[b.p.id].checkOnUpdate)c[b.p.id]._savedData={},c[b.p.id]._savedData[e.p.id+"_id"]=d;var o=e.p.colModel;if("_empty"==d)a(o).each(function(){f=this.name;j=a.extend({},this.editoptions||{});if((m=a("#"+a.jgrid.jqID(f),"#"+h))&&m.length&&null!==m[0])if(q="",j.defaultValue?
(q=a.isFunction(j.defaultValue)?j.defaultValue.call(b):j.defaultValue,"checkbox"==m[0].type?(l=q.toLowerCase(),0>l.search(/(false|0|no|off|undefined)/i)&&""!==l?(m[0].checked=!0,m[0].defaultChecked=!0,m[0].value=q):(m[0].checked=!1,m[0].defaultChecked=!1)):m.val(q)):"checkbox"==m[0].type?(m[0].checked=!1,m[0].defaultChecked=!1,q=a(m).attr("offval")):m[0].type&&"select"==m[0].type.substr(0,6)?m[0].selectedIndex=0:m.val(q),!0===c[b.p.id].checkOnSubmit||c[b.p.id].checkOnUpdate)c[b.p.id]._savedData[f]=
q}),a("#id_g","#"+h).val(d);else{var n=a(e).jqGrid("getInd",d,!0);n&&(a('td[role="gridcell"]',n).each(function(m){f=o[m].name;if("cb"!==f&&"subgrid"!==f&&"rn"!==f&&!0===o[m].editable){if(f==e.p.ExpandColumn&&!0===e.p.treeGrid)g=a(this).text();else try{g=a.unformat.call(e,a(this),{rowId:d,colModel:o[m]},m)}catch(i){g="textarea"==o[m].edittype?a(this).text():a(this).html()}b.p.autoencode&&(g=a.jgrid.htmlDecode(g));if(!0===c[b.p.id].checkOnSubmit||c[b.p.id].checkOnUpdate)c[b.p.id]._savedData[f]=g;f=
a.jgrid.jqID(f);switch(o[m].edittype){case "password":case "text":case "button":case "image":case "textarea":if(" "==g||" "==g||1==g.length&&160==g.charCodeAt(0))g="";a("#"+f,"#"+h).val(g);break;case "select":var j=g.split(","),j=a.map(j,function(b){return a.trim(b)});a("#"+f+" option","#"+h).each(function(){this.selected=!o[m].editoptions.multiple&&(a.trim(g)==a.trim(a(this).text())||j[0]==a.trim(a(this).text())||j[0]==a.trim(a(this).val()))?!0:o[m].editoptions.multiple?-1<a.inArray(a.trim(a(this).text()),
j)||-1<a.inArray(a.trim(a(this).val()),j)?!0:!1:!1});break;case "checkbox":g+="";o[m].editoptions&&o[m].editoptions.value?o[m].editoptions.value.split(":")[0]==g?(a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("checked",!0),a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("defaultChecked",!0)):(a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("checked",!1),a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("defaultChecked",!1)):(g=g.toLowerCase(),0>g.search(/(false|0|no|off|undefined)/i)&&""!==g?(a("#"+f,"#"+h)[b.p.useProp?
"prop":"attr"]("checked",!0),a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("defaultChecked",!0)):(a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("checked",!1),a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("defaultChecked",!1)));break;case "custom":try{if(o[m].editoptions&&a.isFunction(o[m].editoptions.custom_value))o[m].editoptions.custom_value.call(b,a("#"+f,"#"+h),"set",g);else throw"e1";}catch(q){"e1"==q?a.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+a.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose):
a.jgrid.info_dialog(jQuery.jgrid.errors.errcap,q.message,jQuery.jgrid.edit.bClose)}}k++}}),0<k&&a("#id_g",i).val(d))}}function u(){a.each(b.p.colModel,function(a,b){b.editoptions&&!0===b.editoptions.NullIfEmpty&&k.hasOwnProperty(b.name)&&""===k[b.name]&&(k[b.name]="null")})}function t(){var e,f=[!0,"",""],m={},g=b.p.prmNames,j,o,l,n,v,p=a(b).triggerHandler("jqGridAddEditBeforeCheckValues",[a("#"+h),z]);p&&"object"===typeof p&&(k=p);a.isFunction(c[b.p.id].beforeCheckValues)&&(p=c[b.p.id].beforeCheckValues.call(b,
k,a("#"+h),"_empty"==k[b.p.id+"_id"]?g.addoper:g.editoper))&&"object"===typeof p&&(k=p);for(l in k)if(k.hasOwnProperty(l)&&(f=a.jgrid.checkValues.call(b,k[l],l,b),!1===f[0]))break;u();f[0]&&(m=a(b).triggerHandler("jqGridAddEditClickSubmit",[c[b.p.id],k,z]),void 0===m&&a.isFunction(c[b.p.id].onclickSubmit)&&(m=c[b.p.id].onclickSubmit.call(b,c[b.p.id],k)||{}),f=a(b).triggerHandler("jqGridAddEditBeforeSubmit",[k,a("#"+h),z]),void 0===f&&(f=[!0,"",""]),f[0]&&a.isFunction(c[b.p.id].beforeSubmit)&&(f=c[b.p.id].beforeSubmit.call(b,
k,a("#"+h))));if(f[0]&&!c[b.p.id].processing){c[b.p.id].processing=!0;a("#sData",i+"_2").addClass("ui-state-active");o=g.oper;j=g.id;k[o]="_empty"==a.trim(k[b.p.id+"_id"])?g.addoper:g.editoper;k[o]!=g.addoper?k[j]=k[b.p.id+"_id"]:void 0===k[j]&&(k[j]=k[b.p.id+"_id"]);delete k[b.p.id+"_id"];k=a.extend(k,c[b.p.id].editData,m);if(!0===b.p.treeGrid)for(v in k[o]==g.addoper&&(n=a(b).jqGrid("getGridParam","selrow"),k["adjacency"==b.p.treeGridModel?b.p.treeReader.parent_id_field:"parent_id"]=n),b.p.treeReader)b.p.treeReader.hasOwnProperty(v)&&
(m=b.p.treeReader[v],k.hasOwnProperty(m)&&!(k[o]==g.addoper&&"parent_id_

After Oleg pointed me in the right direction (thanks Oleg!). I have managed to resolve this Error.
Using The jquery.jqgrid.src.js (much more readable) I managed to take an educated guess that the problem lay on a column in my Grid that was using a FORMATTER. I then noticed that even when loading the Edit form - the value for this column was not correct - and bacause The edittype was 'select', it was defaulting to the first item in the value list.
The Formatter would take the Value of the column (which could be either a -2, 0 or 1 in this case) and turn it into a gif for display purposes in the column. that worked lovely.
The UnFormatter, however, attempted to turn the image back into it's respective number (based on its title). I was then returning a numeric value ( ie. -2, 0 or 1). I needed to return a string value. (ie. '-2','0' or '1')
So, it seems that for Unformatters, you cannot return numeric values like this.
I have added the working code below for clarity :)
Working formatters
function EnabledFormatter(cellvalue, options, rowObject) {
var cellValueInt = parseInt(cellvalue);
switch (cellValueInt)
{
case 1:
return "<img src='#Url.Content("~/Content/images/tick.gif")' title='Enabled' />";
break;
case -2:
return "<img src='#Url.Content("~/Content/images/tick-grey.png")' title='Inherited' />";
break;
default:
return "<img src='#Url.Content("~/Content/images/cross.gif")' title='Disabled' />";
break;
};
};
function EnabledUnformatter (cellvalue, options, cell) {
var sTitle = $('img', cell).attr('title');
switch (sTitle)
{
case 'Enabled':
return '1';
break;
case 'Inherited':
return '-2';
break;
default:
return '0';
break;
};
};
Broken Unformatter Please note The lack of '' around the values returned. The EnabledFormatter is Unchanged
function EnabledUnformatter (cellvalue, options, cell) {
var sTitle = $('img', cell).attr('title');
switch (sTitle)
{
case 'Enabled':
return 1;
break;
case 'Inherited':
return -2;
break;
default:
return 0;
break;
};
};

Related

How to store a return value in variable flutter

I need a little help.
I have this function in another file and i want to store the return value in a variable, because i dont want to repeat the same code again and again and I want to reuse it as many times I want.
here is the code in another file.
double dropDownIf(dropDownVal, finalVal, valParsed) {
if(dropDownVal == 'm'){
finalVal = valParsed;
} else if(dropDownVal == 'cm'){
finalVal = valParsed/100;
} else if(dropDownVal == 'mm'){
finalVal = valParsed/1000;
}
print('here is the updated value $finalVal');
return finalVal;
}
as you can see that it show the return value in debug console but it doesnt show the value in another page in which i am using this code.
here is the code on another page.
dropDownIf(dropDownValueL, finalLength, lengthParsed);
print(finalLength);
here in this page, the print function shows 0, I have declared the double finalLength = 0; in the beginning of the file. so the print shows 0 instead of the updated value.
the middle value in the dropDownIf function is the return value but it doesnt work.
You need to store the return value of the method in a variable, then use it:
double returnValue = dropDownIf(dropDownValueL, finalLength, lengthParsed);
print(returnValue);

AG-Grid: updateRowData({update: ItemsArray}) affecting all rows instead of selected rows

I'm using Ag-Grid and Angular for this project, and what I'm trying to do is set up shortcut keys to change the 'Status' value of selected rows by pressing associated keys('1'= 'status complete', etc.). There is a built in function called onCellKeyPress() that listens for keystrokes after a row, or rows, has been selected. That's working great, I have a switch case that sends off a value depending on which key is pressed like so:
onCellKeyPress = (e: any) => {
switch(e.event.key) {
case '0': this.rowUpdates('New'); break;
case '1': this.rowUpdates('Completed'); break;
case '2': this.rowUpdates('Needs Attention'); break;
case '3': this.rowUpdates('Rejected'); break;
}
}
It sends a string to my custom function rowUpdates(), that takes the value, goes though the existing Nodes, looks for any that are selected, sets the value on those selected, and pushes them to an array.
Now here's where the trouble starts. updateRowData takes 2 params, first is the type of updating it's doing(add, remove, update), in my case I'm using the latter, and an array of rows to change.
rowUpdates = (value: String) => {
let itemsToUpdate = [];
this.gridOptions.api.forEachNode(rowNode => {
if(rowNode.isSelected() === true) {
const selected = rowNode.data;
selected.status.name = value;
itemsToUpdate.push(selected);
console.log(itemsToUpdate);
}
});
this.gridOptions.api.updateRowData({update: itemsToUpdate});
}
However when I press a key to change the row value it updates every row in my grid. What's extra strange is that I have a method that adds a class to the row depending on the 'Status' value, and only the rows I intended to change receive that class.
I'm stumped. I've console.logged everything in this function and they all return with their intended values. The array always contains the nodes that have been selected and the return value of updateRowData is always that same array. I've tried switching out 'forEachNode' with getSelectedNodes and getSelectedRows to no avail. Any ideas?
Please try this.
updateItems(value: String) {
var itemsToUpdate = [];
this.gridApi.forEachNodeAfterFilterAndSort(function(rowNode, index) {
if (!rowNode.selected) {
return;
}
var data = rowNode.data;
data.status.name = value;
itemsToUpdate.push(data);
});
var res = this.gridApi.updateRowData({ update: itemsToUpdate });
this.gridApi.deselectAll();//optional
}

Protractor wait for all elements to have changed text

I want to wait till first element gets updated to rate same as monthlyRate variable and second element gets updated to rate same as annualRate.
With below code I get:
Failed: Wait timed out after 9008ms
public waitForSubscriptionRates = (rateselector: string, monthlyRate: string, annualRate: string) => {
browser.wait(function(){
element.all(by.css(rateselector)).filter(function(elem, index) {
return elem.getText().then(function(text) {
console.log('text=' + text);
console.log('monthlyRate=' + monthlyRate);
console.log('annualrate=' + annualRate);
return (text === monthlyRate || text === annualRate);
});
}).first().click();
},9000);
}
I'm not sure do I understand your code well.
I assume that there are two selectors - first may contain text of monthlyRate and second annualRate. They can not be mixed, isn't it?
I don't get what you want to click.
Anyway, you can chain ExpectedConditions with or keyword.
See the example in the documentation: http://www.protractortest.org/#/api?view=ProtractorExpectedConditions.prototype.or

Filter getElementsByTagName list by option values

I'm using getElementsByTagName to return all the select lists on a page - is it possible to then filter these based upon an option value, ie of the first or second item in the list?
The reason is that for reasons I won't go into here there are a block of select lists with number values (1,2,3,4,5 etc) and others which have text values (Blue and Black, Red and Black etc) and I only want the scripting I have to run on the ones with numerical values. I can't add a class to them which would more easily let me do this however I can be certain that the first option value in the list will be "1".
Therefore is there a way to filter the returned list of selects on the page by only those whose first option value is "1"?
I am pretty sure that there is a better solution, but for the moment you can try something like:
var allSelect = document.getElementsByTagName("select");
var result = filterBy(allSelect, 0/*0 == The first option*/, "1"/* 1 == the value of the first option*/);
function filterBy(allSelect, index, theValue) {
var result = [];
for (var i = 0; i < allSelect.length; i++) {
if(allSelect[i].options[index].value == theValue ) {
result.push(allSelect[i]);
}
}
return result;
}
I managed to get this working by wrapping a simple IF statement around the action to be performed (in this case, disabling options) as follows:
inputs = document.getElementsByTagName('select');
for (i = 0; i < inputs.length; i++) {
if (inputs[i].options[1].text == 1) {
// perform action required
}
}
No doubt there is a slicker or more economic way to do this but the main thing is it works for me.

tinymce.dom.replace throws an exception concerning parentNode

I'm writing a tinyMce plugin which contains a section of code, replacing one element for another. I'm using the editor's dom instance to create the node I want to insert, and I'm using the same instance to do the replacement.
My code is as follows:
var nodeData =
{
"data-widgetId": data.widget.widgetKey(),
"data-instanceKey": "instance1",
src: "/content/images/icon48/cog.png",
class: "widgetPlaceholder",
title: data.widget.getInfo().name
};
var nodeToInsert = ed.dom.create("img", nodeData);
// Insert this content into the editor window
if (data.mode == 'add') {
tinymce.DOM.add(ed.getBody(), nodeToInsert);
}
else if (data.mode == 'edit' && data.selected != null) {
var instanceKey = $(data.selected).attr("data-instancekey");
var elementToReplace = tinymce.DOM.select("[data-instancekey=" + instanceKey + "]");
if (elementToReplace.length === 1) {
ed.dom.replace(elementToReplace[0], nodeToInsert);
}
else {
throw new "No element to replace with that instance key";
}
}
TinyMCE breaks during the replace, here:
replace : function(n, o, k) {
var t = this;
if (is(o, 'array'))
n = n.cloneNode(true);
return t.run(o, function(o) {
if (k) {
each(tinymce.grep(o.childNodes), function(c) {
n.appendChild(c);
});
}
return o.parentNode.replaceChild(n, o);
});
},
..with the error Cannot call method 'replaceChild' of null.
I've verified that the two argument's being passed into replace() are not null and that their parentNode fields are instantiated. I've also taken care to make sure that the elements are being created and replace using the same document instance (I understand I.E has an issue with this).
I've done all this development in Google Chrome, but I receive the same errors in Firefox 4 and IE8 also. Has anyone else come across this?
Thanks in advance
As it turns out, I was simply passing in the arguments in the wrong order. I should have been passing the node I wanted to insert first, and the node I wanted to replace second.