jqgrid를 사용하여 사이트 목록을 표시하고 있으며 사이트를 추가하거나 편집 할 때 서버 측 유효성 검사를 일부 수행하려고합니다. (양식은 인라인이 아닌 양식 편집이 필요합니다. 여러 가지 이유로 유효성 검사는 서버 측에 있어야합니다.) 전에 이벤트가있는 경우 ajax 요청을 통해 데이터를 확인하는 것이 가장 좋은 방법이라고 생각했습니다. 트리거 됨. 그러나 이것은 그리드의 기존 행을 편집 할 때만 작동하는 것으로 보입니다. 새 행을 추가 할 때 함수가 호출되지 않습니다.Jqgrid를 사용하여 서버 측 유효성 검사를 수행하는 방법?
전에 이 있습니까?을 잘못된 위치에 제출 하시겠습니까?
도움 주셔서 감사합니다. 당신이 beforeSubmit
이벤트를 사용하려면
$("#sites-grid").jqGrid({
url:'/json/sites',
datatype: "json",
mtype: 'GET',
colNames:['Code', 'Name', 'Area', 'Cluster', 'Date Live', 'Status', 'Lat', 'Lng'],
colModel :[
{name:'code', index:'code', width:80, align:'left', editable:true},
{name:'name', index:'name', width:250, align:'left', editrules:{required:true}, editable:true},
{name:'area', index:'area', width:60, align:'left', editable:true},
{name:'cluster_id', index:'cluster_id', width:80, align:'right', editrules:{required:true, integer:true}, editable:true, edittype:"select", editoptions:{value:"<?php echo $cluster_options; ?>"}},
{name:'estimated_live_date', index:'estimated_live_date', width:120, align:'left', editable:true, editrules:{required:true}, edittype:"select", editoptions:{value:"<?php echo $this->month_options; ?>"}},
{name:'status', index:'status', width:80, align:'left', editable:true, edittype:"select", editoptions:{value:"Live:Live;Plan:Plan;"}},
{name:'lat', index:'lat', width:140, align:'right', editrules:{required:true}, editable:true},
{name:'lng', index:'lng', width:140, align:'right', editrules:{required:true}, editable:true},
],
height: '300',
pager: '#pager-sites',
rowNum:30,
rowList:[10,30,90],
sortname: 'cluster_id',
sortorder: 'desc',
viewrecords: true,
multiselect: false,
caption: 'Sites',
editurl: '/json/sites'
});
$("#sites-grid").jqGrid('navGrid','#pager-sites',{edit:true,add:true,del:true, beforeSubmit : function(postdata, formid) {
$.ajax({
url : 'json/validate-site/',
data : postdata,
dataType : 'json',
type : 'post',
success : function(data) {
alert(data.message);
return[data.result, data.message];
}
});
}});
beforeSubmit을 사용하는 것이 이해가되지 않습니다. * 데이터가 서버에 제출되기 전에 분명히 트리거됩니다. 그리고 이전에 제출을 별도로 수행합니다. 유효성 검사를 위해 제출하십시오. 사이트 편집/추가 URL (및 코드)은 단순히 유효성 검사 + 저장 데이터 모두를 처리해야합니다. 그리고 afterSubmit에서 당신은 응답을 확인하게 될 것입니다. 이것은 성공한 저장이나 유효성 검사 오류 일 수 있습니다. –