I want to change the autocomplete options of a complete.ly object based on the selection made in another dropdown list.
I call the updateAuto function through JQuery by doing $("#ddlToWatch").change(updateAuto).
The updateAuto function definition is as follows :
function updateAuto() {
var optionsDD;
if ($("#ddlToWatch").val() == "bla") {
optionsDD = [
'blabla',
'blabla2'
];
};
$("#mycompletelybox").options = optionsDD;
};
It seems like you can't access directly the options using JQuery for complete.ly objects. What is the recommended way to access those if that is indeed the issue ?
Any help welcome.
I ended up initializing the textbox with a global variable
var mybox;
$(function() {
mybox = completely($("#mycompletelybox"), {color:'black'});
}
and using that variable in my code above.
So, instead of
$("#mycompletelybox").options = optionsDD;
use
mybox.options = optionsDD;
Related
I have an object variable which is from a SQL Query. This essentially contains two columns: RecordID and Description. I'm not familiar with JavaScript. But how do I read the specific columns and assign them to a local javascript variable?
Here's the sample code I would like to use with the new User::MyObject structure of multiple columns:
task.run = function () {
var myID = task.variables["User::MyObject"].value;
var myDesc = task.variables["User::MyObject"].value;
alert(myID);
alert(myDesc);
return ScriptResults.Success;
};
EDIT: I am using COZYROC that's why I have a JavaScript Task available in my toolbox. The result set is currently set to Full Result Set and the object is being pushed to User::MyObject via a preceeding SQL Task.
Here's a code from when my User::MyObject was a single result set with single row and single column return (just the Description).
task.run = function () {
var myDesc = task.variables["User::MyObject"].value;
alert(myDesc);
return ScriptResults.Success;
};
I know for VB.NET/C# you can use something like myVariable.Rows[0][1].ToString() but i'm really not sure how that translates to JavaScript.
Within your task function:
1. Set a variable to the object
var MyObject= task.variables["User::MyObject"].value;
2 Access the ID property of your object
MyObject.ID
Complete example to get ID:
task.run = function () {
var MyObject = task.variables["User::MyObject"].value;
alert(MyObject.ID);
return ScriptResults.Success;
};
Example from crazycroc documentation https://desk.cozyroc.com/portal/en/kb/articles/how-c
Is it possible to get the value from NUMBERFORMAT field and use it in custom code?
I wrote a pdf document in the code and I'd like to include the number format that is set in the Set Preferences tab. I would like to know if this is possible and how could I do it?
var userPref = nlapiLoadConfiguration('userpreferences');
var numFormat = userPref.getFieldText('numberformat');
Here is 1.0 approach.
Yes. You can use the N/config module to retrieve this information:
define(['N/config'], function(config) {
// Add some entry point function here
function getUserNumberFormat() {
var generalPrefs = config.load({ type: 'userpreferences', isDynamic: true });
return generalPrefs.getText('NUMBERFORMAT');
}
}
Assume we have the following Object :
var gridViewModelJs =
{"GridViewModel":{"Rows":[{"RowNumber":"1","Id":"6","Name":"FullNameOfUser","NumberOfUsers":"12","RegistrationDate":"10/15/2013"}],"FoundItems":"4","CurrentPage":1,"TotalPages":1,"ItemsPerPage":50,"PagingLinks":""},
"EntityModel":{"Id":0,"PermissionIds":null,"Name":null,"NumberOfUsers":0,"PersianRegistrationDate":null,"RegistrationDate":"0001-01-01T00:00:00","Authorizations":null,"Users":null,"Contents":null}};
var KoEntityViewModel = ko.mapping.fromJS(gridViewModelJs);
ko.applyBindings(KoEntityViewModel);
Above code works, for updating the KoEntityViewModel. I used the following code :
// receivedData is data that returns from jQuery Ajax
// I'm dead sure `receivedData` is correct
var doneFunc = function (receivedData) {
ko.mapping.fromJS(receivedData, KoEntityViewModel.EntityModel);
showDetailsBlock();
};
But nothing update in KoEntityViewModel.EntityModel.
Please guide me how I can update KoEntityViewModel.EntityModel in above sample
When you update the mapping after applying bindings, use three parameters:
ko.mapping.fromJS(receivedData, {}, KoEntityViewModel);
Here's how I'm initializing and building an array:
var newCountyInfo = new Object();
newCountyInfo.name = newCountyName;
newCountyInfo.state = newCountyState;
newCountyInfo.zips = newCountyZips;
newCountyInfo.branchID = newCountyBranchID;
So I have my four elements in the array. I'm then passing newCountyInfo to another function to pull out the elements for display in some HTML elements.
The only way I know how to get to the individual elements in the function that uses them is this:
JSON.parse(JSON.stringify(newCountyValidation)).name
JSON.parse(JSON.stringify(newCountyValidation)).state
... etc...
There's got to be a better/shorter/more elegant way of doing this!
What is it?
Why are you serializing at all? I don't understand what JSON has to do with this, unless you're using web workers, ajax, or something else which demands serialization. Start with object literal syntax:
var newCountyInfo = {
name: newCountyName,
state: newCountyState,
zips: newCountyZips,
branchID: newCountyBranchID
};
And just pass the whole object to the other function:
someOtherFunction(newCountyInfo);
Which can access the fields using plain old property accesses:
function someOtherFunction(foo) {
console.log(foo.name); // whatever was in newCountyname
}
No JSON whatsoever.
Something like this should work just fine:
var newCountyInfo = {
name: newCountyName,
state: newCountyState,
zips: newCountyZips,
branchID: newCountyBranchID
}
function test(newCountyValidation)
{
alert(newCountyValidation.name);
}
test(newCountyInfo);
Consider i am having an object "req".
When i use console.log(req) i get
Object { term="s"}
My requirement is to append an value with the existing object.
My expected requirement is to be like this:
Object { term="s", st_id = "512"}
Is it possible to do the above?
If yes, how ?
Thanks in advance..
There are several ways to do it;
Plain javascript:
var req = { "term" : "s" };
req.st_id = "512";
Because javascript objects behaves like associative arrays* you can also use this:
var req = { "term" : "s" };
req["st_id"] = "512";
jQuery way $.extend():
var req = { "term" : "s" };
$.extend(req, { "st_id" : "512" });
You can do this in a couple of ways:
req.st_id = "512";
or
req["st_id"] = "512";
The second of these is especially useful if the variable name is dynamic, e.g. a variable could be used instead of the string literal:
var key = "st_id";
req[key] = "512";
Yes this is possible, to add properties to a value simply use the following syntax:
req.st_id = "512";