Hello,
I have problem with onTabClick event. When I click the tab, cursor not placed in Form component. I am using dhtmlx 4.0.3. This is my code
function doOnLoad() {
var myTab = new dhtmlXTabBar({
parent: document.body,
tabs: [
{id: “in”, text: “Pembelian (Quantity+)”, active: true},
{id: “barang”, text: “Barang (Produk)”}
]
})
pembelianFormStructure = [
{type: "input", name: "kode_text", label: "Kode", labelWidth: 100, inputWidth: 180}
]
var pembelianForm = myTab.tabs("in").attachForm(pembelianFormStructure);
barangFormStructure = [
{type: "input", name: "kode_text", label: "Kode", labelWidth: 100, inputWidth: 180}
]
var barangForm = myTab.tabs("barang").attachForm(barangFormStructure);
myTab.attachEvent("onTabClick", function(id) {
if (id == "in") {
pembelianForm.setItemFocus("kode_text");
pembelianForm.setFocusOnFirstActive();
//pembelianForm.setItemValue("kode_text", "hello")
};
if (id == "barang") {
barangForm.setItemFocus("kode_text");
barangForm.setFocusOnFirstActive();
//barangForm.setItemValue("kode_text", "barang")
}
})
}
Please help me, what the problem with my code…Thanks
Darya
September 8, 2014, 1:09pm
#2
Hello
You need to paste this line
pembelianForm.setFocusOnFirstActive();
after this
var barangForm = myTab.tabs(“barang”).attachForm(barangFormStructure);
Result:
var barangForm = myTab.tabs("barang").attachForm(barangFormStructure);
pembelianForm.setFocusOnFirstActive();
You need to set focus on first active after form is loaded
I have tried put the codes outside and inside “onTabClick” event. Cursor placed on form input only when page load for the first time. When I clicking second tab, cursor not placed on form. And when I click back to first tab cursor not in form component too.
This is my codes:
var myTab = new dhtmlXTabBar({
parent: document.body,
tabs: [
{id: “in”, text: “Pembelian (Quantity+)”, active: true},
{id: “barang”, text: “Barang (Produk)”}
]
})
pembelianFormStructure = [
{type: “input”, name: “kode_text”, label: “Kode”, labelWidth: 100, inputWidth: 180}
]
var pembelianForm = myTab.tabs("in").attachForm(pembelianFormStructure);
pembelianForm.setFocusOnFirstActive();
barangFormStructure = [
{type: "input", name: "kode_text", label: "Kode", labelWidth: 100, inputWidth: 180}
]
var barangForm = myTab.tabs("barang").attachForm(barangFormStructure);
//pembelianForm.setFocusOnFirstActive();
barangForm.setFocusOnFirstActive();
myTab.attachEvent("onTabClick", function(id) {
if (id == "in") {
var pembelianForm = myTab.tabs("in").attachForm(pembelianFormStructure);
pembelianForm.setFocusOnFirstActive();
};
if (id == "barang") {
var barangForm = myTab.tabs("barang").attachForm(barangFormStructure);
barangForm.setFocusOnFirstActive();
}
})
Thank you
Darya
September 9, 2014, 2:12pm
#4
Try the next code:
var pembelianFormStructure = [
{type: “input”, name: “kode_text”, label: “Kode”, labelWidth: 100, inputWidth: 180}
];
var barangFormStructure = [
{type: “input”, name: “kode_text2”, label: “Kode”, labelWidth: 100, inputWidth: 180}
];
function doOnLoad() { //debugger;
myTab = new dhtmlXTabBar({
parent: document.body,
tabs: [
{id: “in”, text: “Pembelian (Quantity+)”, active: true},
{id: “barang”, text: “Barang (Produk)”}
]
});
barangForm = myTab.tabs("barang").attachForm(barangFormStructure);
pembelianForm = myTab.tabs("in").attachForm(pembelianFormStructure);
pembelianForm.setFocusOnFirstActive();
myTab.attachEvent("onTabClick", function(id) {
if (id == "in") {
pembelianForm.setItemFocus("kode_text");
};
if (id == "barang") {
barangForm.setItemFocus("kode_text2");
}
});
myTab.attachEvent("onSelect", function(id, lastId) {
if (id == "in") {
window.setTimeout(function(){
pembelianForm.setItemFocus("kode_text");
}, 1)
};
if (id == "barang") {
window.setTimeout(function(){
barangForm.setItemFocus("kode_text2");
},1)
}
return true;
})
}
Using another event “onSelect”…problem solved.
Never thinking about this one.
Thank you very much