I've looked around and tried a few things but I can't seem to get it to work. I want to be able to update the value stored in input$someVar from a bit of js code. What I need to on a certain element click, I need to update the input$someVar value. I know there are functions like "updateSelectInput()" but those are called from the server.
I can physically change the value of the data in the HTML that is used int he data attribute and that is displayed, but the server doesnt see this as a change and the input$someVar stays the same.
I have tried
var selectBind = Shiny.inputBindings.bindings[5];
selectBind.binding.setValue('#loc', newValue);
within an event handler, where #loc is the id of the input element, in hope that I could do it that way but this gives me an error.
Is there a way to do the functionality of "updateSelectInput()" within java script in the ui?
Yes, there is a way. Use the JavaScript function Shiny.onInputChange.
// change the value of an input
document.getElementById("id").value = "value";
// report the change to shiny
Shiny.onInputChange("id", "value");
Related
I have a form with a formCommandButtonControl in d365. I want to change the command associated to the button dynamically according to the condition in the code. I can't find any base enum to choose the value.
switch (x)
{
case 1:
formButton.command(New);
break;
case 2:
formButton.command(DeleteRecord);
break;
}
This is the property in the form
How can I choose New and deleteRecord value in x++ code?
Unfortunately, the answer to your question is do not do that and there is no enum.
When dynamically creating command buttons (FormBuildCommandButtonControl vs FormCommandButtonControl), the Microsoft convention has been to just use a constant (#define.New(260)) and reference that.
It is unheard of to dynamically change a command button's command and I don't believe it's done anywhere in the system.
The command button's text most likely won't update dynamically so you'll have change that too.
You should use a regular button for your purposes or create multiple command buttons and adjust their visibility as needed like the comments say.
The most obvious way is to provide two buttons only showing the relevant.
newButton.visible(x == 1);
deleteButton.visible(x == 2);
Mark the AutoDeclaration attribute of the control.
The code placed in init or active method where appropriate.
I have a table inside of appmaker that I've added checkboxes to like so:
I'd like to get a list of the emails from entires that the user checks. At this point I'm not even able to access the status of a single checkbox. This is the current code snippet I tried adding to a button:
console.log(widget.parent.parent.parent.children.Panel1.children.Table3Panel.children.Table3.children.Table3Body.children.Table3Row.children.UserSelectionCheckbox.value);
I get the error:
Cannot read property 'children' of undefined
at Home.Panel1.OuSelectPanel1.Button6.onClick:1:133
I was able to use the autofill to write this entire statement, why can't it find the child object? Is there any way to reference this list directly without going down the tree from the widget or the app root?
For this type of functionality the autofill (intellisense) will not work for you. You need to address the children differently when you try to get a collection of rows from a table. I would suggest code similar to this for your button onClick event:
var rows = widget.root.descendants.Table3Body.children._values;
var emails = [];
for (var i in rows) {
var value = rows[i].children.Checkbox1.value;
if (value) {
emails.push(rows[i].datasource.item.Email);
}
}
console.log(emails);
Again the auto complete code feature simply won't work after you choose the _values, which will return all immediate children of your table body, which is what you want.
based on the 1:133 it seems to be saying that Table3Row has no children. I wonder if using widget.root.descendants.Table3Row might be a different way of doing it address the particular table.
I want to parse a 'pushed' data layer string. I intend to use it to track click events and setup the appropiate funnels in Google Analytics, it looks as follows: products.view.19|view recent product|19
The first part (products.view.19) is the unique page identifier.
The second part (view recent product) is the action.
The last part is (19) is the action identifier, this way actions may be grouped and compared more easily.
So I did the following, I first created a trigger (it fires when a link has the tag 'data-trackclick' in it) which pushes the data value to a variable (variable for datalayer). However, now I want to split that variable in to 3 new variables, as described above. I selected 'javascript macro' for this but somehow it returns 'undefined'. The macro looks as follows:
function() {
var data = {{TrackClickData}};
var pieces = data.split('|');
if (pieces[0].length()) {
return pieces[0];
} else {
return data;
}
}
Obviously this didnt work since it would only run on the initial load and not (like I thought) when the macro was requested, so it should somehow be fired on the 'click' and then set the variables accordingly.
Is this possible to do? Or do I really have to add the dataLayer.push() in script tags?
A few things:
.length() is wrong, the property for array length is .length without the ()
if it exists, pieces[0] is not an array, then .length would return the string length, see How do you check for an empty string in JavaScript? for more standard way of checking for empty strings
Is this possible to do? There's virtually nothing you can't do with GTM, since you can write JavaScript code, you can do whathever you code allows you to do, and splitting a string to use parts of it as variables is certainly within the realm of possibilities.
My advise is to make your code work outside GTM first (eg test it in the browser console), then once it's all working, port it to GTM.
I am new to Web UI, Dojo, Java etc. If you are referring any advance topic please give some reading reference. It will help.
Context:
I have Gridx design using JsonStore, which takes a target + id for URL. With fixed "id" Grid loads well.
I have Dynamic Tree. It is working fine with lazy-loading etc.
Objective:
Based on click (or dblclick) event for a given node in Tree, I have to load Gridx with data. Hence, if tree node "id":7 is clicked, then JsonStore: /target/7 should be fetched and get loaded in Gridx.
Issues:
As you can guess, at start there is no valid "id" property to fill in JsonStore. In click event handler of tree, I will get this value, upon a user click. Hence, can't call gridx.startup() in "ready". Though I have "placed" the widget in "ready".
Hence, I have following snippet to handle,
<
// this function is called from tree event handler
function LatestTabGridxLoad( id ) {
console.log( "ID %s fetched.", id );
LatestTabGridxStore.idProperty = id;
LatestTabGridx.startup();
LatestTabGridx.body.refresh();
}
ready(function()
{
TabLatestAssetTree.startup();
LatestTabGridx.placeAt( "ReportMiddleTabLatestCenterContainer" );
}
Now, trouble is, at first time loading, JsonStore GET fired with /target/ alone, without any "id" without any user click. Hence, server responds with 405. Subsequently, when user clicks, again same HTTP GET without "id" results in HTTP 405. I am not able to somehow feed "id" to the GET URL. I have checked JSON, it is in perfect shape, as it works in standalone table, that is declarative(ly) defined.
Please suggest me ways to link a TREE node through its "id" to Gridx. Also suggest, if approach I am taking is right way to solve this problem.
Sorry, misunderstanding of the question. I thought it was about gridx tree but it is about regular gridx controlled by another widget.
The problem is in this line:
console.log( "ID %s fetched.", id );
LatestTabGridxStore.idProperty = id;
'idProperty' is the name of the JSON attribute which stores the ID. This will not change with each selection. If it is not set, JsonStore will assume it to be 'id'. What you intended to do was to modify the target property of the store to include the ID. This can done directly and will look something like the following (details are application specific)
LatestTabGridxStore.target = (someURL) + '/' + id;
After that, the content of gridx needs to be replaced using the new store setting. There are few ways to do it, the simplest being destroying the current gridx instance and replacing it with another one which uses the altered store.
I have a repeater that populates a component, called 'project'. The project components are given an ID of 'wholeProject'. In all of my functions up until now, I was able to determine how many project components were made by doing the following:
wholeProject.length;
I used this in for loops, for each loops, and for changing the item settings within a project, i.e. something like this:
wholeProject[i].studentName = "Billy Bob";
However, I'm creating a new function that does not seem to like this wholeProject.length reference. I'm using it within the same level as all the others (i.e. the parent level). So far, my function is simply this:
public function getStudentYears():void
{
Alert.show(String(wholeProject.length));
}
when the application loads, the alert message simply does not appear. If I change the alert to something like this:
Alert.show("This is just a test.");
it works just fine. But for some reason, the wholeProject.length doesn't work in this function whereas it does in all my other ones. Anybody have any ideas as to why this is happening?
Use your repeater's data provider length instead.