angucomplete-alt:clearInput error Unable to get property 'originalObject' - javascript

I'm new to angularjs and am trying to use the angucomplete-alt to allow the user to search for worker names. The search works great, but when I try to clear the input box after the user selects a result the box clears but I get this error message...
TypeError: Unable to get property 'originalObject' of undefined or null reference
at $scope.nameSelected (..Worker.php:498:3)
at callOrAssign (..angucomplete-alt.js:167:11)
at Anonymous function (..angucomplete-alt.js:124:11)
at Scope.prototype.$broadcast (..angular.js:18487:15)
at $scope.deleteRow (..Worker.php:471:6)
at fn (Function code:2:153)
at callback (..angular.js:26994:17)
at Scope.prototype.$eval (..angular.js:18161:9)
at Scope.prototype.$apply (..angular.js:18261:13)
at Anonymous function (..angular.js:26999:17)
Everything seems to work fine, but I hate getting a huge error every time.
this is the box
<angucomplete-alt id="workerName"
placeholder="Name"
pause="100"
minlength="2"
selected-object="nameSelected"
remote-url="Suggest_Name.php?term="
remote-url-data-field=""
title-field="value"
input-class="form-control">
</angucomplete-alt>
and this is the clear command
//clear the autocomplete text box
$scope.$broadcast('angucomplete-alt:clearInput','workerName');
thanks to a user's question I think I've figured it out. It looks like the nameSelected function fires when the autocomplete is cleared. Here's nameSelected..
//autocomplete callback function
$scope.nameSelected = function ($item){
if($item != undefined){ //I just added this
//console.log($item.originalObject);
$scope.worker_new.Emp_Name = $item.originalObject.lastname + ', ' + $item.originalObject.firstname;
$scope.worker_new.PDCWorker_EID = $item.originalObject.UWIdNbr;
$scope.worker_new.PCA_Option = $item.originalObject.pca_option;
}
}
adding the check to see if '$item' is undefined has solved my error problem.

Related

Ckeditor - replace

I'm currently working wit the CKEditor.
I have a form where user can fill data inside the CKEditor. When the user clicks the save button ajax is called. Inside the ajax call I replace the data with the form data. Before the ajaxFormOnSuccess() method I'm trying to destroy all the instances and replacing them again.
The destroy works properly but when I try to add an instance again i'm getting the error:
Uncaught TypeError: Cannot read property 'unselectable' of null
at c (ckeditor.js:227)
at a. (ckeditor.js:224)
at a.g (ckeditor.js:10)
at a.CKEDITOR.event.CKEDITOR.event.fire (ckeditor.js:11)
at a.CKEDITOR.editor.CKEDITOR.editor.fire (ckeditor.js:13)
at a.fireOnce (ckeditor.js:12)
at a.CKEDITOR.editor.CKEDITOR.editor.fireOnce (ckeditor.js:13)
at Object. (ckeditor.js:177)
at k (ckeditor.js:161)
at Object.load (ckeditor.js:161)
Here is the code for destroying and adding them again.
$('textarea.ckeditor').each(function () {
var txtBoxID = this.attributes.id.nodeValue;
var editor = CKEDITOR.instances[txtBoxID];
if (editor) {
editor.destroy(true);
}
});
CKEDITOR.replace('GeneralData.TypeOfInsuranceGoods', { autoParagraph: false });
Currently just adding a single instance to test it but I'm getting the error(see above).
Does anyone know what I am doing wrong?
Thank you in behave.
Brent

What does "uncaught exception: out of memory" mean and how do you track the cause? [duplicate]

I am debugging a javascript/html5 web app that uses a lot of memory. Occasionally I get an error message in the console window saying
"uncaught exception: out of memory".
Is there a way for me to gracefully handle this error inside the app?
Ultimately I need to re-write parts of this to prevent this from happening in the first place.
You should calclulate size of your localStorage,
window.localStorage is full
as a solution is to try to add something
var localStorageSpace = function(){
var allStrings = '';
for(var key in window.localStorage){
if(window.localStorage.hasOwnProperty(key)){
allStrings += window.localStorage[key];
}
}
return allStrings ? 3 + ((allStrings.length*16)/(8*1024)) + ' KB' : 'Empty (0 KB)';
};
var storageIsFull = function () {
var size = localStorageSpace(); // old size
// try to add data
var er;
try {
window.localStorage.setItem("test-size", "1");
} catch(er) {}
// check if data added
var isFull = (size === localStorageSpace());
window.localStorage.removeItem("test-size");
return isFull;
}
I also got the same error message recently when working on a project having lots of JS and sending Json, but the solution which I found was to update input type="submit" attribute to input type="button". I know there are limitations of using input type="button"..> and the solution looks weird, but if your application has ajax with JS,Json data, you can give it a try. Thanks.
Faced the same problem in Firefox then later I came to know I was trying to reload a HTML page even before setting up some data into local-storage inside if loop. So you need to take care of that one and also check somewhere ID is repeating or not.
But same thing was working great in Chrome. Maybe Chrome is more Intelligent.

Debugging script Netsuite suitescript in Chrome exception

So I am trying to add a button to the Sales Order form in netsuite that validates certain fields based on what you entered in previous fields. I am having trouble testing and debugging this in google chrome in netsuite. First, here is my code: I am adding the button that calls this function within the client script record.
function vsoeValidate(){
var calc = nlapiGetFieldValue('custbody_cv_vsoe_calculation');
calc = nlapiGetFieldValue('custbody_cv_renewal_rev_amount') - (nlapiGetFieldValue('custbody_cv_vsoe_cola') * nlapiGetFieldValue(1-'custbody_cv_vsoe_partner_disc')) - (nlapiGetFieldValue('custbody_cv_vsoe_bts_fees') * (1-nlapiGetFieldValue('custbody_cv_vsoe_partner_disc'))) /
(nlapiGetFieldValue('custbody_cv_vsoe_software_amt') * (1- nlapiGetFieldValue('custbody_cv_vsoe_multiyear_disc')));
nlapiSetFieldValue('custbody_cv_vsoe_calculation', calc);
var display = nlapiGetFieldValue('custbody_cv_vsoe_calculation_disp');
var bucket = nlapiGetFieldValue('custbody_cv_vsoe_bucket');
if(bucket === 'X'){
return false;
}
if(calc > (nlapiGetFieldValue('custbody_cv_vsoe_bucket.custrecord_cv_vsoe_maintenance_rate') *1.15) || calc < ('custbody_cv_vsoe_bucket.custrecord_cv_vsoe_maintenance_rate'*0.85)){
display = '<div style="; background-color:red; color:white;font-weight:bold;text-align:center">Out of bounds</div>';
return true;
}
else{
display = '<div style="; background-color:green; color:white;font-weight:bold;text-align:center">In bounds</div>';
return true;
}
}
when I click the button I get the error TypeError undefined is not a function.
I am really not sure where to go from here, is it because the logic inside vsoeValidate is not right or am I using the wrong type of function? Any help would be great thank you!
Update: here is the screenshot of my script record!
Try passing the function name as string i.e.
form.addButton('custpage_validatevsoe', 'Validate VSOE', 'vsoeValidate');
You mentioned that you set vsoeValidate as a validateField function. Do you want this function to run when users click the button or when NetSuite's valdiateField event is fired (upon field change, before the value is stored)?
If you want this to run on NetSuite's validateField event, then the function must return true or false; it cannot return void. Right now in your logic, you have:
if (bucket = 'x') {
return;
}
if (bucket = 'x') is an assignment operation, not an equality check. This assignment operation will return 'x', which is a truthy value, so your code will enter that if-block. You then return void (undefined), so my guess is that NetSuite is trying to do something with the result returned by your function but cannot because it returned undefined.
The validateField function also gets passed a parameter that provides the ID of the field being validated.
You will also want to inject some console logging at various points so you can figure out where your script is failing instead of just trying to guess at reading syntax.
Can you provide us with a screenshot of your Script record setup?
Also since you are using a client side script, you don't need to use the pageInit event for adding a custom button.
There is a 'Buttons' subtab, under the 'Scripts' tab when you create the Script record in NetSuite. This subtab is next to the 'Libraries' subtab.
There are two columns here, 'Label' and 'Function'.
So in your case, you can just put 'Validate VSOE' in the Label field and vsoeValidate in the Function field.
Please note that if you do it this way, the button will only be shown when you are creating or editing a record.

DHTMLX Error on dock [ing] an undocked cell

I am having trouble getting an undocked cell in DHTMLX 4 to dock.
When I click on the provided "dock" button(on the undocked cell) I get the error:
Uncaught TypeError: Cannot read property 'close' of null
I also get this same error when assigning the .dock() function to another button.
onclick: function ()
{
// where to undock to
_this.dhxLayout.dhxWins.attachViewportTo("layout_div");
// init & undock window
var popup_cell = _this.dhxLayout.cells("c");
popup_cell.undock(0,0,800,600);
var popup_window = _this.dhxLayout.dhxWins.window("c");
popup_window.button("minmax1").hide();
popup_window.setText(" ");
// things to do when window is opened
popup_cell.attachEvent("onUnDock", alert("undocked"));
// assigning .dock() to another button, neither work
popup_window.button("park").attachEvent("onClick", function(popup_window){_this.dhxLayout.cells("c").dock();});
// popup_window.button("park").attachEvent("onClick", function(popup_window){popup_cell.dock()});
}
The traceback takes me to c=this.layout.dhxWins.window(this.conf.name);c.close(); so I am guessing that c is somehow undefined? Is there an argument/parameter I am supposed to be passing in the .dock(foo)? The API shows no examples with it.
Any help is greatly appreciated!
I missed out on this: http://forum.dhtmlx.com/viewtopic.php?f=5&t=37052
And followed it to change the offending line of:
c=this.layout.dhxWins.window(this.conf.name);c.close();
(in dhtmlx.js)
to
c=g.dhxWins.window(this.conf.name);c.close();
and the problem is fixed!

Form Field Verification Not Working

I've got some form verification code that doesn't seem to be working correctly, and I can't figure out why.
function isTextFieldEmpty(textField){
//return true or false depending on whether or not there is any text in the field
console.log("Checking to see if the current field is empty...");
var val = textField.value; //val is the text from the current field
console.log("The current value of 'val' is: " + val);
if(val.length < 1){
return true;
}else{
return false;
}
}
The error I get is: "Uncaught TypeError: Cannot read property 'length' of undefined". Sure enough, my console log says that the value of 'val' is undefined.
I'm sure I'm missing something, but I'm still learning JS and can't figure out what it is. Any suggestions?
Edit: Here is what I'm passing to the function:
var uName = document.getElementById("unionname");
var noUnionName = isTextFieldEmpty(uName);
'unionname' is the id of the texfield that I'm trying to validate. Here is the relevant HTML:
<div class="formBox">
<label for="unionname">Union Name</label>
<input type="text" name="unionname" id="unionname" value="" class="wide"/>
<span class="feedback good">Sample good message</span>
</div>
You are declaring var val locally in that function. Try declaring it globally by putting it at the top of your script; don't need to set it, just declare it.
I've gotten it working. Seems that the validation function was fine; the problem was in the way I was calling it.
window.onload = justDoIt;
function justDoIt() {
var uName = document.getElementById("unionname");
uName.onblur = function(){
clearMessages(uName); // clear out old feedback for this field
var noUnionName = isTextFieldEmpty(uName);
This is how I ended up calling the function.
Ironically, it seems that the faulty .onblur code that I left out of my previous example may have been the cause of my problem. But I'm really not sure.

Categories