Display dhtmlxtree in more than one place - dhtml

I've created hhtmlxtree, displayed correct using below code:
<script>
var myTree;
myTree = new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
myTree.setImagePath("/library/dhtmlxTree/codebase/imgs/dhxtree_skyblue/");
myTree.setImagePath("/library/dhtmlxTree/skins/terrace/imgs/dhxtree_terrace/");
myTree.setXMLAutoLoading('customer/tree');
myTree.setDataMode("json");
</script>
<div id="treeboxbox_tree"></div>
I want to display same tree in more than one place like '#treeboxbox_tree'. How to do this without initialize object every time for a tree.

In case of DHTMLX components, you will need to run the init code for each place where you need to have a tree. You can't just clone the already created component.

Related

Getting dynamic selector in Cypress

I am working on Cypress and want to get a dynamic selector that always changes.
For example,
<div class="Select-value">
<input id = "react-select-9--value">
I want to get this input value but the number "9" for the ID changes every time I run the test. There is no other selector I can pick for this and there are other inputs on the same page with IDs like react-select-10--value, react-select-11--value.
What is the right way to get this type of selector in Cypress?
Thanks in advance!
You can aim for a relative element.
The only one shown above is the <div>, so using that as an example
cy.get('div[class="Select-value"]')
.find('[id^="react-select"]') // ^= means "starts-with"
.eq(0) // first one, because it looks like that above
Post a bigger example of the HTML if that's no good for you.

How to find the highest attribute in a dataset, then display the "name" associated with that

I'm still relatively new to programming and I have a project I am working on. I am making a staff efficiency dashboard for a fictional pizza company. I want to find the quickest pizza making time and display the time and the staff members name to the user.
With the data charts it has been easy. Create a function, then use dc, e.g dc.barChart("#idOfDivInHtmlPage")
I suspect I might be trying to be too complicated, and that I've completely forgotten how to display any outputs of a js function to a html page.
I've been using d3.js, dc.js and crossfilter to represent most of the data visually in an interactive way.
Snippet of the .csv
Name,Rank,YearsService,Course,PizzaTime
Scott,Instore,3,BMC,96
Mark,Instore,4,Intro,94
Wendy,Instore,3,Intro,76
This is what I've tried so far:
var timeDim = ndx.dimension(function(d) {
return [d.PizzaTime, d.Name]
});
var minStaffPizzaTimeName = timeDim.bottom(1)[0].PizzaTime;
var maxStaffPizzaTimeName = timeDim.top(1)[0].PizzaTime;
}
then in the html
<p id="minStaffPizzaTimeName"></p>
<script type="text/javascript" src="static/js/graph.js">
document.write("minStaffPizzaTimeName");
</script>
You are surely on the right track, but in javascript you often have to consider the timing of when things will happen.
document.write() (or rather, anything at the top level of a script) will get executed while the page is getting loaded.
But I bet your data is loaded asynchronously (probably with d3.csv), so you won't have a crossfilter object until a bit later. You haven't shown these parts but that's the usual way to use crossfilter and dc.js.
So you will need to modify the page after it's loaded. D3 is great for this! (The straight javascript way to do this particular thing isn't much harder.)
You should be able to leave the <p> tag where it is, remove the extra <script> tag, and then, in the function which creates timeDim:
d3.select('#minStaffPizzaTimeName').text(minStaffPizzaTimeName);
This looks for the element with that ID and replaces its content with the value you have computed.
General problem solving tools
You can use the dev tools dom inspector to make sure that the p tag exists with id minStaffPizzaTimeName.
You can also use
console.log(minStaffPizzaTimeName)
to see if you are fetching the data correctly.
It's hard to tell without a running example but I think you will want to define your dimension using the PizzaTime only, and convert it from a string to a number:
var timeDim = ndx.dimension(function(d) {
return +d.PizzaTime;
});
Then timeDim.bottom(1)[0] should give you the row of your original data with the lowest value of PizzaTime. Adding .Name to that expression should retrieve the name field from the row object.
But you might have to poke around using console.log or the interactive debugger to find the exact expression that works. It's pretty much impossible to use dc.js or D3 without these tools, so a little investment in learning them will pay off big time.
Boom, finally figured it out.
function show_fastest_and_slowest_pizza_maker(ndx) {
var timeDim = ndx.dimension(dc.pluck("PizzaTime"));
var minPizzaTimeName = timeDim.bottom(1)[0].Name;
var maxPizzaTimeName = timeDim.top(1)[0].Name;
d3.select('#minPizzaTimeName')
.text(minPizzaTimeName);
d3.select('#maxPizzaTimeName')
.text(maxPizzaTimeName);
}
Thanks very much Gordon, you sent me down the right path!

cloned elements cannot be selected after jquery customSelect plugin installation

I am in a bit of a pickle with this form and i would really appreciate some help.
After installing the customSelect() jquery plugin, i was no longer able to select the cloned select box elements on my form.
For an example, go to...
http:// gator1016.hostgator.com /~tamarind/index.php/en/book-now.html
Click on the second slide >> click on the "add a package" button >> try and change one of the cloned select box values.
Does anyone have any suggestions as to why this is? I'm under a bit of pressure to get this fixed.
Thanks in advance.
You are running .customSelect() in a seperate script tags previous to the rest of your form script. So here is the current order of events:
customSelect takes all given selects and appends a customizable <span> next to each (this is what you styled to achieve the desired look). It also attaches event listeners to those very spans so they can properly interact with their corresponding select element.
A user clicks "add another package", you clone the entire block of form elements including the custom spans that the plugin appended.
It is important to note that in doing this, you are not copying the event listeners, just the elements. Right now, even if you ran customSelect again upon cloning, you would likely have some kind of issue because the original span would still be there.
The solution to your problem would be to keep a reference to a clone of your form block that has not already had customSelect applied. Then each time you insert a new form block, you need to apply customSelect to the "vanilla" form block.
Here is a reduced example for you
HTML
<form action="" id="myForm">
<div id="formBlock">
<select><option>one</option><option>two</option></select>
</div>
</form>
<button id="addNew">add new</button>
jQuery
//do this first:
var formBlock = $('#formBlock').clone();
//now .customSelect();
$('#formBlock select').customSelect();
$('#addNew').click(function(e){
e.preventDefault();
var newFormBlock = formBlock.clone().appendTo('#myForm'); //clone the reference to un-modified form block!!!
newFormBlock.attr({
id:'' //dont want duplicate id's
});
newFormBlock.find('select').customSelect();
});
Demo: http://jsfiddle.net/adamco/ZZGJZ/1/
You also can cleanup the elements added by the plugin, and launch again customSelect:
$('form').find('span.customselect').remove(); //remove the span
$('form').find('select.hasCustomSelect').removeAttr("style"); //clean inline style
$('form select').customSelect( { customClass: "customselect" } ); // fire again customSelect

Getting UI form to render inside HTML table in GAS

In Google Sites, I am trying to add a short form consisting of a text box and a submit button as a cell in a row inside an html table. One copy of the form for each row in the table. I am trying to collect input data for each table row.
HTML File:
<html>
...
function showForm(){ // https://developers.google.com/apps-script/gui_builder#including
var app=UiApp.createApplication();
app.add(app.loadComponent("myGui"));
return app;
}
...
<table><tr><td><?=showForm()?></td></tr></table>
...
</html>
I then call the .html file from my doGet() function in my .gs file using HtmlService.createTemplateFromFile() method.
The table renders properly, except where I expect the form to appear, I instead get the text/string "UiApplication" instead of the text box + submit button combo.
Am I on the right track? Please help.
It's the wrong track.
You can't mix & match components from HtmlService and UiApp. GUI Builder is a packaged UiApp component.
Just stick with a FlexTable and fill the table cells with your builder component. But don't forget to set a prefix:
var flextab = app.createFlexTable();
for (row=0; ...)
for (col=0; ...)
flextab.setWidget(row, col, app.loadComponent("myGui", {"prefix": "row"+row+"col"+col});
BTW - you can only have one UiInstance in your web app. Call UiApp.createApplication() only once. If you need the UiInstance later on, you can always find it with UiApp.getActiveApplication().

jQuery children of cloned element not responding to events

Summary
I am using jQuery to clone a div ("boxCollection") containing groups ("groupBox") each of which contains a set of inputs. The inputs have change events tied to them at $(document).ready, but the inputs inside the cloned divs do not respond to the event triggers. I can not get this to work in IE7, IE8, or FF3.
Here is my sample code:
HTML:
<div class="boxCollection"><div class="groupBox" id="group_1"><input type="text"></input></div></div>
jQuery events:
$(".groupBox[id*='group']").change(function(){
index = $(this).attr("id").substring(6);
if($("input[name='collection_"+index+"']").val() == "")
{
$("input[name='collection_"+index+"']").val("Untitled Collection "+index);
}
});
jQuery clone statement:
$(".boxCollection:last").clone(true).insertAfter($(".boxCollection:last"));
Use live() to automatically put event handlers on dynamically created elements:
$(".groupBox[id*='group']").live("change", function() {
...
});
You appear to be putting a change() event handler on a <div> however (based on your sample HTML). Also, I would recommend not using an attribute selector for this. You've given it a class so instead do:
$("div.groupBox ...")...
Lastly, you are trying to give each text input a unique name. You don't say what your serverside technology is but many (most?) will handle this better than that. In PHP for example you can do:
And $_POST will contain an element "box" with an array of three values.
I'm not sure if this will work, but I'm going to give it a shot and say that you need to assign live events
$(".groupBox[id*='group']").live('change', function() { });
You'll probably have a problem with change and live in IE6/7, so I advise you to use the livequery plugin to resolve that issue.

Resources