Hi
I'm trying to stop a new row being added with the press of Enter on the new row. The reason for this is that we have required field validators on some fields, but not all, so if the user clicks in a field that does not have a validator and presses enter it saves this row without performing the validation.
According to the forum post http://es.infragistics.com/community/forums/t/66546.aspx - we are supposed to be able to trap the KeyDown event but this event does not seem to fire if we press enter in either the New Row or if pressing enter while editing a cell. The event DOES fire if I press any alphanumeric keys. This is the javascript we have on the KeyDown event and the window.alert does not get displayed when Enter is pressed but does for other keys.
function WebDataGridDebt_Grid_KeyDown(sender, eventArgs){ window.alert('keydown'); if (eventArgs.get_browserEvent().keyCode == 13) { enterKey = true; }}
Can you please let me know the best method for disabling the Enter key on the new row (ie, I don't want this to commit the row)
Thanks
Marcus
Hello Marcus,
Yes it has been a while and yet, I am glad that you managed to resolve this issue. Thank you for your feedback.
Hi Ivaylo
I'm sure your suggestion would work fine but this issue was from more than 6 months ago so we have solved our problem by going about things in a completely different way.
Regards,
Hello,
I was just wondering did you have a chance to try my suggestion. If you have any concerns or questions, please feel free to contact me, I will be glad to help you.
Hello Marcus, Thank you for posting in the community!
Instead of checking for the KeyDown event, it is possible to check the cell values of the row to be added. In case of null value, the RowAdding event could be canceled using something similar as these code lines:
<EditingClientEvents RowAdding="CheckCellsValidation" />
function CheckCellsValidation(sender, eventArgs) {
var cellsArray = []; var value1 = eventArgs.get_row().get_cellByColumnKey("DepartmentID").get_value(); var value2 = eventArgs.get_row().get_cellByColumnKey("DepartmentName").get_value();
cellsArray.push(value1); cellsArray.push(value2);
for (var i in cellsArray) { if (cellsArray[i] === null) { eventArgs.set_cancel(true); } } }
Sorry, should have left environment details.
We are using VS2012, IG version 20122.2031 and IE 9 on Windows 7.
Cheers.