iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
I want to validate data Client-Side before a Row is Added or Updated.
To validate I want to compare two values.
The First Value is in a WebGridColumn with the Default Edit Type. I have no problem getting it's value by using rowObject.GetCells().GetNamedItem("Quantity_WebGridColumn").Value.
The Second value is in a WebGridColumn with the EditType of WebComboNET. The WebColumn has Multiple Columns and I want the value in the 3rd column of the selected row. In the Client-Side Event OnExitEditMode I am able to use the editObject to get the value using editObject.element.GetSelectedRow().cells[2].innerText. However, I can not figure out how to get the WebGridEditObject in the OnBeforeUpdate Event using it's parameters controlId, tblName and rowObject.
How can I get the Value of the 3rd Column in the Selected Row of a WebCombo Column in a WebGrid Row?
Thanks,
Doug
Hi,
I had to modify OnBeforeUpdate to set selectLastRow = null;
if(!retVal) selectLastRow = rowObject.KeyValue; else selectLastRow = null;
I had to do a simlar thing for OnBeforeAdd to set newRowTemp = null;
if(!retVal) newRowTemp = rowObject.GetCells(); else newRowTemp = null;
If there is a validation problem and subsequently it is corrected, these variables need to cleared.
Additionally, for fillNewRow, a check needs to be done for null because the column is not visible
var newRowActivated = false; for (var i = 0; i < newRowCells.length; i++) { if (newRowCells[i] != null) { newRowCells[i].SetText(newRowTempCells[i].Text); newRowCells[i].SetValue(newRowTempCells[i].Value); if (!newRowActivated) { newRowCells[i].ActivateEdit(); newRowActivated = true; } } }
Hi Douglas Badin,
Actually, to get the Object of WebCombo that integrated with WebGrid, we can simply get that object by using ISGetObject("WebCombo").
However, when I tried your scenario, there are some problem that I encountered. First, we cannot retrieve the value of WebCombo before we show drop down list of WebCombo to render the data. Nevertheless, I have tried to create this scenario using time out function to retrieve the specific data. Unfortunately, with this code, the event update is triggered before we can see the value of WebCombo. Here is the snippet:
function WebGrid1_OnBeforeUpdate(controlId, tblName, rowObject) { var WebGrid1 = ISGetObject(controlId); var WebCombo = ISGetObject("WebCombo1"); WebCombo.SetText(rowObject.RowElement.cells[2].innerText); WebCombo.ShowDropDown(); setTimeout(function() { alert(WebCombo.GetRows()[0].RowElement.cells[3].innerText); }, 1000); return true; }
Yet, it will be fine if the scenario is, during the editing, we actually open the WebCombo itself. By this, we can actually retrieve the specific data.
Best Regards,
Andi Santoso
I see what you say.
In an Add Scenario, the user will have accessed the WebCombo and everything is fine.
In an Update Scenario, the user may not have accessed the WebCombo and the SelectedRow is residue from the previous WebCombo access.
Is there a way to Canel the Update Server-Side, say in the UpdateRow Event?
The other thought I had was to use HiddenDataMember for the WebGridColumn that contains the WebCombo and on the Client-Side OnExitEditMode modify the HiddenDataMember attribute. Hopefully I can access the modified HiddenDataMember attribute in the Client-Side OnBeforeAdd and OnBefore Update Events to do a comparison.
Do you think it will work?
What is best?
You could cancel the update row by returning false in the Update server side event handler. Here is the snippet:
protected void WebGrid1_UpdateRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e){ e.ReturnValue = false;}
However afterward you will need to refresh the WebGrid to resynchronize the data.
WebGrid HiddenDataMember property will only be available for the field available in the WebGrid data source. In your scenario, you will need to use CustomAttributes property during InitializeRow server side event to hold the field data. In the shown example, the Phone field is buffered in the CustomerID cell element. Here is the InitializeRow server side event:
protected void WebGrid1_InitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e){ //GetHiddenMember function will retrieve phone number based on CustomerID e.Row.Cells.GetNamedItem("CustomerID").CustomAttributes = "Phone = '" + GetHiddenMember(e.Row.Cells.GetNamedItem("CustomerID").Value.ToString()) + "'";}
The snippet to retrieve the phone field during OnBeforeUpdate client side event:
function WebGrid1_OnBeforeUpdate(controlId, tblName, rowObject) { var grid = ISGetObject(controlId); var rowObj = grid.GetSelectedObject().GetRowObject(); var cells = rowObj.GetCells(); var customer = cells.GetNamedItem("CustomerID"); var phone = customer.GetElement().attributes["Phone"].value; //Process phone variable return true;}
1. Is it possible to have more than one CustomAttributes? If so how do I delimit them or add them?
2. How can I add and set the attribute Client-Side for new rows?
I am trying to set the attributes in the Client-Side OnExitEditMode with the following code:
editObject.cellElement.setAttribute("Phone", Phone_String)
This does not work if it is a new row and throws an error. It works fine for an existing row.
3. Now that I have modified the attributes Client-Side, how do I access the modified CustomAtributes in the Server-Side AddRow an UpdateRow Events?
If you could like to add more than 1 custom attribute during InitializeRow server side event, just seperate the custome attribute with a single space. For example:
protected void WebGrid1_InitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e){ //GetHiddenMember function will retrieve phone number based on CustomerID e.Row.Cells.GetNamedItem("CustomerID").CustomAttributes = "Phone = '" + GetHiddenMember(e.Row.Cells.GetNamedItem("CustomerID").Value.ToString()) + "' PhoneType='LandLine'";}
If you would like to add custom attribute for new row, please use the OnAfterAdd client side event handler. You will need to retrieve the key value and add the custom attribute to the newly added WebGrid row. Here is the snippet:
function WebGrid1_OnAfterAdd(controlId, tblName, rowObject, xmlResponseObject){ var WebGrid1 = ISGetObject(controlId); var htmlRowXml = ISXml.GetNodeText(xmlResponseObject, "isnet.webui.webgrid/htmlRow"); var keyValue = document.createElement(htmlRowXml).keyValue; setNewAtributeCell(keyValue); return true;}function setNewAtributeCell(keyValue){ var WebGrid1 = ISGetObject("WebGrid1"); var rowNew = WebGrid1.RootTable.GetRowByKeyValue(keyValue); if (rowNew == null) { setTimeout(function() { setNewAtributeCell(keyValue) }, 15); } else { rowNew.GetCell("CustomerID").GetElement().setAttribute("Phone", "555-1234"); }}
In order to pass infromation from the client side to server side, you will need to use the AddInput function. This information will be hold in the Request object in the server side. Here is the snippet:
function WebGrid1_OnBeforeUpdate(controlId, tblName, rowObject) { var grid = ISGetObject(controlId); var rowObj = grid.GetSelectedObject().GetRowObject(); var cells = rowObj.GetCells(); var customer = cells.GetNamedItem("CustomerID"); var phone = customer.GetElement().attributes["Phone"].value; //Process phone variable grid.AddInput("PhoneJS", phone); return true;}
I was trying to use the CustomAttributes in a comparison for validation since the WebCombo may not have been used for the Update.
In the Add scenario, the Client-Side OnAfterAdd is too late because based on it's value I may not want to Add the row.
I think I will need to use a combination of things to get a value for comparison.
For Updates, I can use CustomAttributes that are populated in the Server-Side InitializeRow and Client-Side OnExitEditMode Events.
For Adds I could use Andi's suggestion, WebCombo.GetRows()[0].RowElement.cells[3].innerText, since the new row will be the last row that has used the WebCombo.
Unless you have a different idea?
I do not have any objection for the workaround you suggested.
Since in your case, the WebCombo field must be filled, so the WebCombo.GetRows()[0].RowElement.cells[3].innerText function in the add scenario will always return the correct value.
I am using the Client-Side OnBeforeAdd and OnBeforeUpdate Events to validate the data entered.
For each event if I return false, the Add or Update does not Add or Update the database as expected.
SCENARIO 1:
After entering data on a new row and tabbing off the last editable coloumn, the OnBeforeAdd Event fires which returns false and focus always remains on the new row which is good
No problem here.
SCENARIO 2:
Ater udpating data on an existing row, when I tab off the last editable column in row the OnBeforeUpdate Event fires which returns false and focus goes to the next row if one is available. If it is the last row, it remains on the last row.
How do I keep focus on the row being updated if there exists other rows after it after returning false from the OnBeforeUpdate Event?
SCENARIO 3:
After updating data on an existing, clicking on another row causes the OnBeforeUpdate Event to fire and focus goes to the row clicked on.
How do I keep focus on the row being updated after returning false from the OnBeforeUpdate Event?
SCENARIO 4:
After entering data in a new row, when I click on another row, the OnBeforeAdd Event is not fired. Focus goes to the clicked row and all data entered in the new row is lost.
How do I keep focus on the new row and keep the data entered?
For scenario 2-4, the workaround would be utilizing the OnSelectRow to re-select the previously selected row, in addition to re-populate the new row (scenario 4).
In both scenario 2 and 3, during OnBeforeUpdate client side event handler you will need to buffer the row key value and using the buffered row key value in the OnRowSelect event handler you will need to reselect the previous row. Here is the snippet:
var selectLastRow = null;function WebGrid1_OnBeforeUpdate(controlId, tblName, rowObject){ var grid = ISGetObject(controlId); var retVal = false; //Line of code to determine return value if(!retVal) selectLastRow = rowObject.KeyValue; return retVal;}function WebGrid1_OnRowSelect(ctrlId){ var grid = ISGetObject(ctrlId); if (selectLastRow != null) { var rowKey = selectLastRow; selectLastRow = null; setTimeout(function() { grid.ClearSelection(); grid.RootTable.GetRowByKeyValue(rowKey).Select(); grid.RootTable.GetRowByKeyValue(rowKey).GetCell("CustomerID").ActivateEdit(); grid.RootTable.GetRowByKeyValue(rowKey).SetDataChanged(); grid.MarkEdit(); }, 15); }}
For scenario 4, it will be similar with the scenario 2 and 3 however, in this scenario you will be utilizing the OnBeforeAdd event handler:
var newRowTemp = null;function WebGrid1_OnBeforeAdd(controlId, tblName, rowObject){ var grid = ISGetObject(controlId); var retVal = false; //Determine the return value if(!retVal) newRowTemp = rowObject.GetCells(); return retVal;}function fillNewRow(newRowTempCells){ var grid = ISGetObject("WebGrid1"); setTimeout(function() { var newRowObj = grid.GetRowByElement(grid.RootTable.GetNewRow()); grid.ClearSelection(); newRowObj.Select(); newRowObj.BeginEdit(); var newRowCells = newRowObj.GetCells(); for (var i = 0; i < newRowCells.length; i++) { newRowCells[i].SetText(newRowTempCells[i].Text); newRowCells[i].SetValue(newRowTempCells[i].Value); if (i == 0) newRowCells[0].ActivateEdit(); } newRowObj.SetDataChanged(); grid.MarkEdit(); }, 15);}function WebGrid1_OnRowSelect(ctrlId){ var grid = ISGetObject(ctrlId); if (newRowTemp != null) { var rowKeyCells = newRowTemp; newRowTemp = null; fillNewRow(rowKeyCells); }}
For scenario 4, in order for the WebGrid to always trigger the OnBeforeAdd event handler you will need to use the NewRowLostFocusAction="AlwaysUpdate" attribute under WebGrid LayoutSettings
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname