I have a gridview using devexpress tools that is populated on page load. When I select a row I have button that will allow me to edit the information in that row by popping up an edit box that allows me to change the information. The issue I am having is when they click that button the data that was behind the gridivew could have changed so I want to be able to query the database again (using some parameters from the selected row) when that edit button is clicked.
Here is the query that is ran when the 'edit' button is clicked.
function ShowPopupEditInventory() {
$.when(getFocusedInventory()).then(function (x) {
popupControlEditInventory.Show();
});
function getFocusedInventory(s, e) {
grid.GetRowValues(grid.GetFocusedRowIndex(), 'StorageLocation;LP;Sku_Alpha;LotCode;ExpirationDate;FIFOReferenceDate;ManufactureDate;InventoryStatus;SellableUnitQuantity;ReceiveDate;InventoryDetailID;Area', getFocusedInventoryValues);
}
function getFocusedInventoryValues(values) {
var fStorageLocation = values[0];
var fLP = values[1];
var fSku_Alpha = values[2];
var fLotCode = values[3];
var fExpirationDate = values[4];
var fFIFOReferenceDate = values[5];
var fManufactureDate = values[6];
var fInventoryStatus = values[7];
var fSellableUnitQuantity = values[8];
var fReceiveDate = values[9];
var fInventoryDetailID = values[10];
var fArea = values[11];
editInventoryStorageLocation.SetText(fStorageLocation);
editInventoryLP.SetText(fLP);
editInventoryItem.SetText(fSku_Alpha);
editInventoryQty_OldValue.SetText(fSellableUnitQuantity);
editInventorySts_OldValue.SetText(fInventoryStatus);
editInventoryLot_OldValue.SetText(fLotCode);
txtEditInventoryLot.SetText(fLotCode);
$(".editInventoryLot").val(fLotCode);
editInventoryStatus.SetValue(fInventoryStatus)
editInventoryUnitQuantity.SetText(fSellableUnitQuantity);
editInventoryDTL_No.SetText(fInventoryDetailID);
editInventoryNotes.SetText('');
$(".editInventoryAdjustmentCode").prop("selectedIndex", 0);
editInventoryArea.SetText(fArea);
editInventoryLot.Focus();
btnOKEditInventory.SetEnabled(true);
}
}
I am working on Sahi and got stuck with this issue.
Issue: I am getting [object] as a value instead of value "true" while asserting the button attribute.
Code:
File 1: category.sah
_include("newCatLib.sah");
_click($tabCategory);
_assertEqual("Category Details", _getText($heading), "");
disabledBtn($lowLvlCatEdtBtn, true, $subLvlCatEdtBtn, true);
File 2: newCatLib.sah
var $tabCategory = _span("title[2]");
var $heading = _heading3("page-title");
var $highLvlCatDrpdn = _select(0);
var $lowLvlCatDrpdn = _select(1);
var $subLvlCatDrpdn = _select(2);
var $lowLvlCatEdtBtn = _button(0);
var $subLvlCatEdtBtn = _button(1);
function disabledBtn($lowLvlCatEdtBtn, $boolean1, $subLvlCatEdtBtn, $boolean2) {
var $isDisabledBtn1 = _getAttribute($lowLvlCatEdtBtn, "disabled");
_assertEqual($boolean1, $isDisabledBtn1);
var $isDisabledBtn2 = _getAttribute($subLvlCatEdtBtn, "disabled");
_assertEqual($boolean2, $isDisabledBtn2);
}
Execution Log:
[-] **disabledBtn([object], true, [object], true)**
_assertEqual(true, true) [257 ms] [08:28:29.537]
_assertEqual(true, true) [253 ms] [08:28:29.790]
I have checked Button accessor in HTML code which is correct.
Please, refactor your code and leave everything out which is not relevant for the question, that makes your question easier to understand and will most likely answer it
var $btn1 = _button(0);
var $btn2 = _button(1);
disabledBtn($btn1);
disabledBtn($btn2);
function disabledBtn($btn) {
var $isDisabled = _getAttribute($btn, "disabled");
_assertTrue($isDisabled);
}
I have a extended datatable, RICHFACES 3.3.3 with sorting and filtering enabled. The table is rendered dynamically. Based on the requirement, I need to disable certain rows(which contain editable fields) when the table is displayed.
I have that logic written in a Javascript function rowBlur(), and call it whenever the page is displayed. Hence, when the table is loaded the required rows are disabled as expected. The problem is whenever I filter/sort the table, the disabled rows get enabled again.
Is there any way I can call the javascript function whenever filter or sort happens?
Here is the code:
HtmlExtendedDataTable dynamicDataTable = new HtmlExtendedDataTable();
dynamicDataTable.setOnkeydown("filterAllOnEnter(event)");
function filterAllOnEnter(event) {
if(event.keyCode == 13) {
jQuery(".rich-filter-input").blur();
rowblur();
return false;
} else
return true;
}
// js code////////////
<script>
function show(){
val = '${myController.mergeWorkMap}';
}
</script>
<script>
function rowblur(){
for(var i=0;i<7;i++){
var firstCol = "myForm:dynamicTable:"+i+":col0" ;
var secondCol = "myForm:dynamicTable:"+i+":col1" ;
var merge =document.getElementById(firstCol).textContent;
var work =document.getElementById(secondCol).textContent;
var obj = JSON.parse(val).mergeWorkMap;
if(!(work == obj[merge])){
var col3 = "myForm:dynamicTable:" + i + ":col3";
var col4 = "myForm:dynamicTable:" + i + ":col4";
var col5 = "myForm:dynamicTable:" + i + ":col5";
var col6 = "myForm:dynamicTable:" + i + ":col6";
document.getElementById(col3).disabled = true;
document.getElementById(col4).disabled = true;
document.getElementById(col5).disabled = true;
document.getElementById(col6).disabled = true;
}
}
}
</script>
The rowblur() won't work properly on filtering, and on sorting the columns it won't work at all.
I am wondering how to add a duplicate panel underneath the previous existing panel ("productOtherPanel") using the "Add Product" button. I would like the new panel to be inserted below the existing "productOtherPanel" and above the "Add Product" button. I would also like this new panel to contain the same drop down list and text box as the original "productOtherPanel". I need this panel to duplicate an infinite number of times. Is this possible?
function doGet(e) {
var app = UiApp.createApplication();
var productOtherPanel = app.createHorizontalPanel().setId('productOtherPanel');
var productPanel = app.createVerticalPanel().setId('productPanel');
var productList = app.createListBox().setName("productList").setId('productList');
productList.addItem("8:1 Compressed Blocks");
productList.addItem("8:1 Compressed Briquettes");
var pricePerTonPanel = app.createVerticalPanel().setId('pricePerTonPanel');
var pricePerTonTextBox = app.createTextBox().setId("pricePerTonTextBox").setName("pricePerTonTextBox")
.setText("$0.00");
var buttonPanel = app.createVerticalPanel().setId('buttonPanel');
var button = app.createButton("Add Product");
app.add(productOtherPanel);
productOtherPanel.add(productPanel);
productPanel.add(productList);
productOtherPanel.add(pricePerTonPanel);
pricePerTonPanel.add(pricePerTonTextBox);
app.add(buttonPanel);
buttonPanel.add(button);
return app;
}
Try to see if this code is what you are looking for:
function doGet(e) {
var app = UiApp.createApplication();
var productOtherPanel = app.createVerticalPanel().setId('productOtherPanel');
var productPanel = app.createHorizontalPanel().setId('productPanel');
// Product list dropdown
var productList = app.createListBox().setName("productList").setId('productList');
productList.addItem("8:1 Compressed Blocks");
productList.addItem("8:1 Compressed Briquettes");
// Product Price Textbox
var pricePerTonTextBox = app.createTextBox().setId("pricePerTonTextBox").setName("pricePerTonTextBox").setText("$0.00");
productPanel.add(productList);
productPanel.add(pricePerTonTextBox);
var buttonPanel = app.createVerticalPanel().setId('buttonPanel');
var button = app.createButton("Add Product");
button.addClickHandler(app.createServerHandler("addProductHandler").addCallbackElement(productOtherPanel));
app.add(productOtherPanel);
productOtherPanel.add(productPanel);
app.add(buttonPanel);
buttonPanel.add(button);
return app;
}
function addProductHandler(e) {
var app = UiApp.getActiveApplication();
var productPanel = app.createHorizontalPanel().setId('productPanel');
// Product list dropdown
var productList = app.createListBox().setName("productList").setId('productList');
productList.addItem("8:1 Compressed Blocks");
productList.addItem("8:1 Compressed Briquettes");
// Product Price Textbox
var pricePerTonTextBox = app.createTextBox().setId("pricePerTonTextBox").setName("pricePerTonTextBox").setText("$0.00");
productPanel.add(productList);
productPanel.add(pricePerTonTextBox);
var panel = app.getElementById("productOtherPanel");
panel.add(productPanel);
return app;
}
TL;DR (Short synopsis):
I have recreated the admin "Add" button in my own project. However, when I hit "save" on the parent form, it is not recognizing the new select element.
Whole Story:
I have that functionality working in my own project... almost. I need help figuring out the last step. As it is now, I have a "+" button, I click it, a popup shows up, I add a new object, hit save, popup closes and that new item is now in my select box and selected - just like the admin page. However, when I hit save on this parent form, I get the error that I've selected an item not in the list. Of course, since the page has reloaded, my new item is part of the list and I just hit save again and it works. Of course, I need it to save on the first time!
The basic setup is my Parent model is called System and the foreign key model is called Zone. The Zone model lists how many zones a system has (1 zone,2 zones,10 zones, etc...)
OK, some code:
The "Add" link in the template of the parent form:
Add
In my New_Zone view, after saving the new zone, I check if the popup GET variable is 1, if so, return a javascript function. Here's the view:
...
if form.is_valid():
f = form.save(commit=False)
pk_value = f.numOfZones
form.save()
obj = Zone_Info.objects.get(numOfZones=pk_value)
if isPopup == "1":
return HttpResponse('<script>opener.closeAddPopup(window, "%s", "%s");</script>' % (escape(pk_value), escape(obj)))
...
And here is my Javascript (largely copied from the admin javascript:
function html_unescape(text) {
// Unescape a string that was escaped using django.utils.html.escape.
text = text.replace(/</g, '<');
text = text.replace(/>/g, '>');
text = text.replace(/"/g, '"');
text = text.replace(/'/g, "'");
text = text.replace(/&/g, '&');
return text;
}
function windowname_to_id(text) {
text = text.replace(/__dot__/g, '.');
text = text.replace(/__dash__/g, '-');
return text;
}
function showAddPopup(triggeringLink, pWin) {
var name = triggeringLink.id.replace(/^add_/, '');
href = triggeringLink.href;
var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
win.focus();
return false;
}
function closeAddPopup(win, newID, newRepr) {
newID = html_unescape(newID);
newRepr = html_unescape(newRepr);
var name = windowname_to_id(win.name);
var elem = document.getElementById(name);
if (elem) {
if (elem.nodeName == 'SELECT') {
var o = new Option(newRepr, newID);
elem.options[elem.options.length] = o;
o.selected = true;
} else if (elem.nodeName == 'INPUT') {
if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
elem.value += ',' + newID;
} else {
elem.value = newID;
}
}
} else {
var toId = name + "_to";
elem = document.getElementById(toId);
var o = new Option(newRepr, newID);
SelectBox.add_to_cache(toId, o);
SelectBox.redisplay(toId);
}
win.close();
}
I took a look at this question and it seems that I am doing precisely the same thing.
Any ideas on how to get that last step of getting the form to recognize the new select element?
Thanks!
I Figured it Out
The problem was what I was passing to my closeAddPopup javascript function. Essentially, I was passing garbage values.
Here's what I originally had in my New_Zone view (which didn't work):
...
if form.is_valid():
f = form.save(commit=False)
pk_value = f.numOfZones
form.save()
obj = Zone_Info.objects.get(numOfZones=pk_value)
if isPopup == "1":
return HttpResponse('<script>opener.closeAddPopup(window, "%s", "%s");</script>' % (escape(pk_value), escape(obj)))
...
It's a pretty stupid mistake on my part (clearly it's late). I was assigning f to the field numOfZones which I thought was the pk and sending that to the script.
Now, the working view looks like this:
if form.is_valid():
obj = form.save()
pk_value = obj.pk
if "_popup" in request.REQUEST:
return HttpResponse('<script>opener.closeAddPopup(window, "%s", "%s");</script>' % (escape(pk_value), escape(obj)))
Anyway... thanks to... well, Stackoverflow. I don't think I would have solved the problem without posting the question and rereading my code on stackoverflow.