Dojo to show/hide DIVs which contains programmaticaly generated combo boxes - dojo

I am a newbie to Dojo. Here is the issue i had. Pleas help.
When select State radio button, State combo box should appear. When select Region radio button, Region combo box should appear. But my codes seem not working.
Fiddle project is here
require([
'dojo/dom',
'dojo/dom-construct',
'dojo/dom-style',
'dojo/query',
'dojo/on',
'dojo/store/Memory',
'dijit/form/ComboBox',
'dojo/domReady!'
], function (dom, domConstruct,domStyle,query,on, Memory, ComboBox) {
var stateStore = new Memory({
data: [
{name:"Alabama", id:"AL"},
{name:"Alaska", id:"AK"},
{name:"American Samoa", id:"AS"},
{name:"Arizona", id:"AZ"},
{name:"Arkansas", id:"AR"},
{name:"Armed Forces Europe", id:"AE"}
]
});
var regionStore = new Memory({
data: [
{name:"North Central", id:"NC"},
{name:"South West", id:"SW"}
]
});
var comboState = new ComboBox({
id: "stateSelect",
name: "state",
store: stateStore,
searchAttr: "name"
}, "state").startup();
var comboRegion = new ComboBox({
id: "regionSelect",
name: "region",
store: regionStore,
searchAttr: "name"
}, "region").startup();
domStyle.set(dom.byId('state'), "display", "block");
domStyle.set(dom.byId('region'), "display", "none");
on(query('.radio'),'change',function(){
query('.query').forEach(function(divElement){
domStyle.set(divElement, "display", "none");
});
domStyle.set(dom.byId(this.dataset.target), "display", "block");
});
});
.hidden {
display: none;
}
<input class="radio" data-target="state" type="radio" name="selection" value="state">State
<input class="radio" data-target="region" type="radio" name="selection" value="region">Region
<div id="state" class="query hidden"></div>
<div id="region" class="query hidden"></div>

It is more straightforward to query and then connect lke:
query('.radio').on('change', function(){
alert("bing")
})

Related

use Dojo to style a programmatically generated combo box

I want to set the text size for a programmatically generated combo box using dojo codes below. The width and height work but not the font-size.
var cboState = new ComboBox({
id: "usastate",
name: "usastate",
style:{width: "100%", height: "40px", fontsize: "20px"},
placeholder: "Select a State",
store: stateStore,
searchAttr: "name",
autocomplete: true
});
Change fontsize to fontSize and it will work.
var cboState = new ComboBox({
id: "usastate",
name: "usastate",
style:{width: "100%", height: "40px", fontSize: "20px"},
placeholder: "Select a State",
store: stateStore,
searchAttr: "name",
autocomplete: true
});
Or, you can also pass the style as a string:
var cboState = new ComboBox({
id: "usastate",
name: "usastate",
style:"width: '100%'; height: '40px'; font-size: '20px'",
placeholder: "Select a State",
store: stateStore,
searchAttr: "name",
autocomplete: true
});
Well, I have added running sample. along with added custom styles.
require([
"dojo/store/Memory", "dijit/form/ComboBox", "dojo/domReady!"
], function(Memory, ComboBox){
var stateStore = new Memory({
data: [
{name:"Alabama", id:"AL"},
{name:"Alaska", id:"AK"},
{name:"American Samoa", id:"AS"},
{name:"Arizona", id:"AZ"},
{name:"Arkansas", id:"AR"},
{name:"Armed Forces Europe", id:"AE"},
{name:"Armed Forces Pacific", id:"AP"},
{name:"Armed Forces the Americas", id:"AA"},
{name:"California", id:"CA"},
{name:"Colorado", id:"CO"},
{name:"Connecticut", id:"CT"},
{name:"Delaware", id:"DE"}
]
});
var comboBox = new ComboBox({
id: "usastate",
name: "usastate",
style:{width: "200px", height: "28px", fontSize: "20px"},
placeholder: "Select a State",
store: stateStore,
searchAttr: "name",
autocomplete: true
}, "stateSelect").startup();
});
<script data-dojo-config="async: 1"
src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/claro/claro.css" media="screen">
<body class="claro">
<input id="stateSelect">
</body>
Hoping this will help you :)

Dgrid Store Issue: Data not displaying

Just started with DOJO and Dgrid.
I've got this simple dgrid using a Memory store.
However the grid in the web page stay empty. Only the header is displayed.
....
#import "./dgrid/css/dgrid.css";
<script src="./dojo/dojo.js"
data-dojo-config="async: true, parseOnLoad: true, isDebug: true">
</script>
<script language="javascript">
require
(
[
"dojo/_base/declare",
"dojo/_base/array",
"dgrid/List",
"dgrid/Grid",
"dgrid/Keyboard",
"dgrid/Editor",
"dgrid/extensions/ColumnResizer",
"dijit/form/NumberTextBox",
"dstore/Memory",
"dojo/parser",
"dojo/domReady!",
"dijit/TooltipDialog",
"dijit/form/DropDownButton",
"dijit/layout/TabContainer",
"dijit/layout/ContentPane"
],
function(
declare, arrayUtil, List, Grid, Keyboard, Editor, ColumnResizer, NumberTextBox, Memory
){
var prevpds =[
{itemnu: "TEST", itemna: "", batchn: "", cqty: 5, sqty: 5, sz: 5},
{itemnu: "TEST 44", itemna: "", batchn: "", cqty: 1, sqty: 2, sz: 3}
];
var pdsstore = new Memory({data: prevpds});
var getColumns = [
{ label: "Item Number", id: "itemnu", field: "text", editor: "text" },
{ label: "Item name", id: "itemna", field: "text", editor: "text" },
{ label: "Batch number", id: "batchn", field: "text", editor: "text" },
{ label: "Concerned Qty", id: "cqty", field: "floatnumber", editor: "NumberTextBox" },
{ label: "Sold Qty", id: "sqty", field: "floatnumber", editor: "NumberTextBox" },
{ label: "Size/ Diameter", id: "sz", field: "floatnumber", editor: "NumberTextBox" }
];
var PdsGrid=declare([Grid, Keyboard, Editor, ColumnResizer]);
window.grid = new PdsGrid(
{
store: pdsstore,
columns: getColumns
}, "pdstable2"
);
}
);
</script>
You have at least two problems.
Firstly, assuming you're using dgrid 0.4 (which I assume since you're also using dstore), you should be setting collection instead of store.
Secondly, the base List and Grid modules do not read from stores; you will want to use either OnDemandGrid or the Pagination extension.
OnDemandList and OnDemandGrid docs
Pagination docs

More choices in FilteringSelect

How to change "more choices" label in the filteringselect.Kindly help me resolve the issue.Below is the code i tried,which is the normal code used in FilteringSelect Example i executed this in notepad++.
<html>
<head>
<link rel="stylesheet" href="dijit/themes/claro/claro.css">
<script>dojoConfig = {parseOnLoad: true}</script>
<script src='dojo/dojo.js'></script>
<script>
require([
"dojo/store/Memory", "dijit/form/FilteringSelect", "dojo/domReady!"
], function(Memory, FilteringSelect){
var stateStore = new Memory({
data: [
{name:"Alabama", id:"AL"},
{name:"Alaska", id:"AK"},
{name:"American Samoa", id:"AS"},
{name:"Arizona", id:"AZ"},
{name:"Arkansas", id:"AR"},
{name:"Armed Forces Europe", id:"AE"},
{name:"Armed Forces Pacific", id:"AP"},
{name:"Armed Forces the Americas", id:"AA"},
{name:"Alifornia", id:"AA"},
{name:"Aolorado", id:"AO"},
{name:"Aonnecticut", id:"AT"},
{name:"Aelaware", id:"AE"},
{name:"Blabama", id:"BL"},
{name:"Blaska", id:"BK"},
{name:"Bmerican Samoa", id:"BS"},
{name:"Brizona", id:"BZ"},
{name:"Brkansas", id:"BR"},
{name:"Brmed Forces Europe", id:"BE"},
{name:"Brmed Forces Pacific", id:"BP"},
{name:"Brmed Forces the Americas", id:"BA"},
{name:"Balifornia", id:"BA"},
{name:"Bolorado", id:"BO"},
{name:"Bonnecticut", id:"BT"},
{name:"Belaware", id:"BE"},
{name:"Dlabama", id:"DL"},
{name:"Dlaska", id:"DK"},
{name:"Dmerican Samoa", id:"DS"},
{name:"Drizona", id:"DZ"},
{name:"Drkansas", id:"DR"},
{name:"Drmed Forces Europe", id:"DE"},
{name:"Drmed Forces Pacific", id:"DP"},
{name:"Drmed Forces the Americas", id:"DA"},
{name:"Dalifornia", id:"DA"},
{name:"Dolorado", id:"DO"},
{name:"Dnecticut", id:"DT"},
{name:"Delaware", id:"DE"}
]
});
var filteringSelect = new FilteringSelect({
id: "stateSelect",
name: "state",
value: "CA",
store: stateStore,
forceWidth:true,
pageSize:10,
searchAttr: "name"
}, "stateSelect");
});
</script>
<style type="text/css">
.dijitInputField
{
font-size:13;
}
.dijitPlaceHolder
{
font-size:13;
}
.dijitMenuItem
{
font-size:0.8em;
}
</style>
</head>
<body class="claro">
<input id="stateSelect">
<p>
<button onclick="alert(dijit.byId('stateSelect').get('value'))">Get value</button>
<button onclick="alert(dijit.byId('stateSelect').get('displayedValue'))">Get displayed value</button>
</p>
</body>
</html>
Yes it's possible, but it's not easy. Dojo defined the "More choices" message in their localized messages, which you can see here.
You cannnot change them directly, but you can override the method where it's used. That's the tricky part, after reading the code I noticed that dropdowns are loaded by using the dropDownClass property which is by default _ComboBoxMenu. This class is where the message is actually used (actually it's a mixin), so we need to subclass this class and extend its behaviour, for example:
var CustomizedMenu = declare([_ComboBoxMenu], {
buildRendering: function() {
this.inherited(arguments);
this.nextButton.innerHTML = "More states"; // New text
}
});
As you can see here, we change the html content of the nextButton to something else in the buildRendering method. It's here where it's originally placed, so we replace it afterwards, that's why we use this.inherited(arguments); first because that means that the superclass function is first executed.
Afterwards we just change the dropDownClass of the select, like this:
var filteringSelect = new FilteringSelect({
id: "stateSelect",
name: "state",
value: "CA",
dropDownClass: CustomizedMenu, // Just change it
store: stateStore,
forceWidth:true,
pageSize:10,
searchAttr: "name"
}, "stateSelect");
You can see the complete code example on this JSFiddle.

Moving and Relocating HTML elements

The following code works fine.But when the drop-down list is displayed it should not override the button elements named get value and get displayed value below it..instead the buttons should movedown when the dropdown is displayed and after a particular item is selected the button shoud come to the original position.
<html >
<head>
<link rel="stylesheet" href="dijit/themes/claro/claro.css">
<script>dojoConfig = {parseOnLoad: true}</script>
<script src='dojo/dojo.js'></script>
<script>
require([
"dojo/store/Memory", "dijit/form/FilteringSelect", "dojo/domReady!"
], function(Memory, FilteringSelect){
var stateStore = new Memory({
data: [
{name:"Alabama", id:"AL"},
{name:"Alaska", id:"AK"},
{name:"American Samoa", id:"AS"},
{name:"Arizona", id:"AZ"},
{name:"Arkansas", id:"AR"},
{name:"Armed Forces Europe", id:"AE"},
{name:"Armed Forces Pacific", id:"AP"},
{name:"Armed Forces the Americas", id:"AA"},
{name:"California", id:"CA"},
{name:"Colorado", id:"CO"},
{name:"Connecticut", id:"CT"},
{name:"Delaware", id:"DE"}
]
});
var filteringSelect = new FilteringSelect({
id: "stateSelect",
name: "state",
value: "CA",
store: stateStore,
searchAttr: "name"
}, "stateSelect");
var filteringSelect = new FilteringSelect({
id: "stateSelect1",
name: "state",
value: "CA",
store: stateStore,
searchAttr: "name"
}, "stateSelect1");
});
</script>
</head>
<body class="claro">
<input id="stateSelect"><br/>
<br/>
<br/>
<input id="stateSelect1">
<input id="stateSelect">
<p>
<button onclick="alert(dijit.byId('stateSelect').get('value'))">Get value</button>
<button onclick="alert(dijit.byId('stateSelect').get('displayedValue'))">Get displayed value</button>
</p>
</body>
</html>
I'm not sure what you mean by "should not override the button elements" because it certainly should. The drop down menu is supposed to be an overlay, it's not part of the page. Whether or not you want it to be part of the page is different.
You cannot easily do this with the filtering select. The filtering select appends the div it uses to hold options, to the bottom of the page. You cannot show it in the normal flow of the page. You will have to create a custom widget that appends its options inside a container directly below the select input.
But I don't know what you are trying to solve by doing this. My advice would be to leave it as is unless you have a really good reason to change it. The drop down menu is a pretty well-ingrained component of GUIs, so changing the behavior of it is not recommended.
Edit:
If you want to limit the height of the drop-down. Set the "maxHeight" of the filteringSelect.
var filteringSelect = new FilteringSelect({
id: "stateSelect",
name: "state",
value: "CA",
store: stateStore,
searchAttr: "name",
maxHeight: 40
}, "stateSelect");
Here is a fiddle. http://jsfiddle.net/8sh24/

Dojo TabContainer doesn't get formatted correctly until after I do an Inspect Element

I have a Dojo DataGrid with a few rows of data. When I click on a row, I have a TabContainer created in another <div>. Here's what it ends up looking like:
The formatting for the TabContainer is incorrect. However, after I do an "Inspect Element", the formatting corrects itself:
However, the Submit button disappears after the formatting is corrected.
Here's the code I use to create the DataGrid and TabContainer:
<div id="r_body">
<div id="r_list">
</div>
<div id="r_form">
<div data-dojo-type="dijit/form/Form" id="parameters_form" data-dojo-id="parameters_form" encType="multipart/form-data" action="" method="">
{% csrf_token %}
<div>
<div id="r_tab_container"></div>
</div>
<div>
<p></p>
<button id="submit_parameters" dojoType="dijit/form/Button" type="submit" name="submitButton" value="Submit">
Submit
</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
require([
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojox/grid/DataGrid" ,
"dojo/data/ItemFileWriteStore" ,
"dojo/dom",
"dojo/domReady!"
], function(BorderContainer, ContentPane, DataGrid, ItemFileWriteStore, dom){
// create a BorderContainer as the top widget in the hierarchy
var bc = new BorderContainer({
style: "height: 500px; width: 230px;"
}, "r_list");
/*set up data store*/
var data = {
identifier: "id",
items: []
};
data.items.push({ id: 'some_id', description: 'some_description',
var store = new ItemFileWriteStore({data: data});
/*set up layout*/
var layout = [[
{'name': 'Title', 'field': 'description', 'width': '200px', 'noresize': true}
]];
/*create a new grid*/
var r_list_grid = new DataGrid({
region: "left",
id: 'r_list_grid',
store: store,
structure: layout,
rowSelector: '0px'
});
bc.addChild(rt_list_grid);
bc.startup();
list_grid.on("RowClick", gridRowClick);
function gridRowClick(evt){
var idx = evt.rowIndex;
var rowData = list_grid.getItem(idx);
var r_url = rowData['url'][0];
var r_id = rowData['id'][0]
require(["dojo/dom", "dojo/request/xhr", "dojo/dom-form", "dijit/layout/TabContainer", "dijit/layout/ContentPane", "dojo/ready", "dojo/domReady!"],
function(dom, xhr, domForm, TabContainer, ContentPane, ready){
var url = window.location.pathname + "dev/" + r_id + "/" + r_url + "/";
xhr(url, {
method: "get"
}).then(
function(response){
var json_response = JSON.parse(response);
var fields_dict = json_response['fields_dict'];
var tc = new TabContainer({
style: "height: 100%; width: 100%;"
}, "r_tab_container");
for(var key in fields_dict) {
var content_string = '';
var fields = fields_dict[key];
for(var field in fields) content_string += '<div>' + field + '</div>';
var tcp = new ContentPane({
title: key,
content: content_string
});
tc.addChild(tcp);
}
tc.startup();
},
function(error){
//Error stuff
}
);
});
}
});
</script>
So what's going here and how do I fix the TabContainer formatting? Thanks!
I had to do a tc.resize(); after I do the tc.startup();