问题
I am using jqgrid for listing and basic crud operations. On one of the pages there are many nullable fields present on the form. When some values are left blank when adding the entity, it saves those fields in db with null (which is fine). But when same field is edited in jqgrid edit popup, textboxes for these fields contain . How can I solve this problem
below figure is the update dialog that appears when I click a row in grid and select edit
UPdate 2
I don't have jqgrid.editform.js but the code Oleg mentioned was directly present in jquery.JQGrid.min.js. I removed the lines and now that code looks like
switch(C[G].edittype)
{
case "password":
case "text":
case "button":
case "image":
case "textarea":
if(A==" "||A==" "||(A.length==1 && A.charCodeAt(0)==160)) {
A = "";
alert("here");
}
alert(A);
a("#"+r,"#"+v).val(A);
break;
case "select":
I have put two alert messages to check if the code path is executed but I found no alert when running the page. What could be wrong here.
Thanks
回答1:
I suppose you should just use the corresponding editoptions option to solve the problem:
editoptions: {NullIfEmpty: true}
UPDATED: If I understand correctly your problem now you can use beforeSubmit
or onclickSubmit
callback of form editing to modify or to delete all empty values from the postdata
parameter. You can for example use for-in
loop to enumerate all properties of posdata
. If the value of some parameter is empty you can use delete
to remove the property or use = null
to change empty string to null
. In both cases you should have null
as the values of empty editing values.
UPDATED 2: The version 3.6.5 which you use is really very old. Fortunately I have the version of jqGrid in my archive. I hope that the reason of your problem is bug in the old version of the code. If you use non-minimized version of jqGrid you can open grid.formedit.js
file and remove lines 832-833:
$("#"+nm,"#"+fmid).val(tmp);
break;
between case "image":
and case "textarea":
. The code should look like in the current version of jqGrid: see here. To fix the problem in minimized version of jqGrid you should search for the text case "button":case "image":
and remove a("#"+r,"#"+v).val(A);break;
which is directly after case "button":case "image":
and before case "textarea":
.
来源:https://stackoverflow.com/questions/14848311/jqgrid-edit-popup-show-nbsp-in-fields-having-null-values