Forum


18:22

05/02/2009

I'm using form edit, and I can't seem to successfully add a record. When I click the submit button, I get the following error:
e is undefined
../jquery.jqGrid-3.8.1/js/jquery.jqGrid.min.js (line 250)
Here is my code:
<html>
<head>
<script type="text/javascript" src="/EMBED/JS/jquery-ui-1.8.13.custom/js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="/EMBED/JS/jquery.tools.min.js"></script>
<script type="text/javascript" src="/EMBED/JS/jquery-ui-1.8.13.custom/js/jquery-ui-1.8.13.custom.min.js"></script>
<script type="text/javascript" src="/SCRAP/JS/jquery.jqGrid-3.8.1/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="/SCRAP/JS/jquery.jqGrid-3.8.1/js/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="/EMBED/JS/jquery.maskedinput-1.3.min.js"></script>
<script src="/SCRAP/JS/fieldValidation.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('button').button();
// Customer Grid
$("#custGrid").jqGrid({
url: 'EMFMCF2',
datatype: "json",
mtype: "GET",
colNames: ['Customer No.','Name','Address','','City','State','Zip','Phone','Email','Fax','Tax Body Code'],
colModel: [
{name:'id', index:'ECACNO', width:100, align:'center', editable:true, formoptions:{elmsuffix:'(*)'}, editoptions:{size:6, maxlength:6}, editrules:{required:true, maxValue:999999, number:true}},
{name:'name', index:'ECNAME', width:200, align:'left', editable:true, formoptions:{elmsuffix:'(*)'}, editoptions:{size:25, maxlength:25}, editrules:{required:true}},
{name:'addr1', index:'ECADDR1', width:100, align:'left', hidden:true, editable:true, editoptions:{size:30, maxlength:30}, editrules:{edithidden:true}},
{name:'addr2', index:'ECADDR2', width:100, align:'left', hidden:true, editable:true, editoptions:{size:30, maxlength:30}, editrules:{edithidden:true}},
{name:'city', index:'ECCITY', width:150, align:'center', editable:true, formoptions:{elmsuffix:'(*)'}, editoptions:{size:20, maxlength:15}, editrules:{required:true}},
{name:'state', index:'ECSTATE', width:100, align:'center', editable:true, edittype:'select', formoptions:{elmsuffix:'(*)'}, editoptions:{dataUrl:"STATESELBX?responseFmt=html&blankOption=true"}/*, editrules:{required:true}*/},
{name:'zip', index:'ECZIP', width:100, align:'center', hidden:true, editable:true, formoptions:{elmsuffix:'(*)'}, editoptions:{size:5, maxlength:5}, editrules:{edithidden:true, maxValue:99999, number:true, required:true}},
{name:'phone', index:'ECPHONE', width:100, align:'center', hidden:true, editable:true, editoptions:{size:12, maxlength:14}, editrules:{edithidden:true}},
{name:'email', index:'ECEMAIL', width:100, align:'center',hidden:true, editable:true, editoptions:{size:25, maxlength:25}, editrules:{edithidden:true}},
{name:'fax',index:'ECFAX', width:100, align:'center', hidden:true, editable:true, editoptions:{size:12, maxlength:14}, editrules:{edithidden:true}},
{name:'taxBdy',index:'ECTXBOD',width:100, align:'center', hidden:true, editable:true, editoptions:{size:7, maxlength:7}, editrules:{edithidden:true, maxValue:9999999, number:true}}
],
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false
},
width: 900,
height: 250,
rowNum: 10,
rowList: [10,20,30],
pager: '#custPager',
sortname: 'ECACNO',
viewrecords: true,
sortorder: "asc",
editurl: "EMFMCF3",
altRows: true
});
// Edit Customer
$("#editButton").click(function(){
var gr = $("#custGrid").jqGrid('getGridParam','selrow');
if( gr != null ) {
$("#custGrid").jqGrid('editGridRow',gr,{
height: 360,
width: 340,
reloadAfterSubmit: true,
editCaption: "Edit Customer",
modal: true,
closeAfterEdit: true,
recreateForm: true, //Recreate form every time so that Add and Edit forms can be different
beforeShowForm: function(form) { //Hide Key Field(s)
$('#tr_id', form).hide();
prepForm(id);
}
});
}
else { alert("Please select a customer to edit."); }
});
// Add New Customer
$("#addButton").click(function(){
$("#custGrid").jqGrid('editGridRow',"new",{
height: 380,
width: 340,
reloadAfterSubmit: true,
addCaption: "Add Customer",
modal: true,
closeAfterAdd: true,
recreateForm: true,
beforeShowForm: function(id){
prepForm(id);
},
beforeSubmit: function(){
var city = $('#city').val();
var state = $('#state').val();
var zip = $('#zip').val();
valCityStateZip(city,state,zip);
$('.tooltip').hide();
},
afterSubmit:function(){
alert('afterSubmit');
}
});
});
// Add Autocompletes, Tooltip, and Phone and Fax Formats
function prepForm(id){
customerNameAutocomplete(id);
cityStateZipAutocomplete();
// Add Tooltip
$('#name').attr("title","This is a wildcard search");
$('#name').tooltip({
position: "center right",
offset: [-2,10],
effect: "fade",
opacity: 0.7
});
// Format Phone and Fax Fields
$('#phone').mask("(999) 999-9999");
$('#fax').mask("(999) 999-9999");
}
// City, State, Zip Autocomplete
function cityStateZipAutocomplete(){
$('#city').autocomplete({
source: "ACCSZ",
minLength: 1,
select: function(event,ui){
$('#state').val(ui.item.state);
$('#zip').val(ui.item.zip);
}
});
}
// Delete Customer
$('#deleteButton').click(function(){
var gr = $('#custGrid').jqGrid('getGridParam','selrow');
if (gr != null) {
$('#custGrid').jqGrid('delGridRow',gr,{
url: "EMFMCF3",
reloadAfterSubmit: true,
msg: "Delete Customer?"
});
} else {
alert("Please select a customer to delete.");
}
});
// Validate Customer Number
$('#id').live('blur',function(){
$.getJSON("EMVALCST",{customer:$('#id').val()},function(c){
var response = c[0].response;
if(response == 'unavailable'){
$('#FormError td').html("Customer No. already in use.");
$('#FormError').show();
$('#id').focus().select();
$('#sData').hide();
}
if(response == 'available'){
$('#FormError').hide();
$('#sData').show();
$('#name').val(c[0].name);
$('#id').val(c[0].custNo);
$('#addr1').val(c[0].add1);
$('#addr2').val(c[0].add2);
$('#city').val(c[0].city);
$('#state').val(c[0].state);
$('#zip').val(c[0].zip);
$('#phone').val(c[0].phone);
$('#email').val(c[0].email);
$('#fax').val(c[0].fax);
$('#taxBdy').val(c[0].taxCode);
return true;
}
if(response == 'notFound'){
$('#FormError td').html('Invalid Customer Number');
$('#FormError').show();
$('#id').focus().select();
$('#sData').hide();
}
});
});
// Validate City, State, and Zip Code
function valCityStateZip(city,state,zip){
var id = 'form#FrmGrid_custGrid.FormGrid';
var msg = '';
$.getJSON("VALCSZ",{city:city, state:state, zip:zip},function(v){
$('#FormError').hide();
if (v.errCode == 'Y') {
//$('#FormError td').html(v.errMsg);
return[false,v.errMsg];
$('#FormError').show();
}
});
}
// Customer Name Autocomplete
function customerNameAutocomplete(id) {
$('#name').autocomplete({
source: "EMACCN",
minLength: 1,
select: function(event,ui){
var number = ui.item.num;
$('#vendor').val(number);
$('#customerNumber').val(number);
$('#id').val(ui.item.custNo);
$('#addr1').val(ui.item.add1);
$('#addr2').val(ui.item.add2);
$('#city').val(ui.item.city);
$('#state').val(ui.item.state);
$('#zip').val(ui.item.zip);
$('#phone').val(ui.item.phone);
$('#email').val(ui.item.email);
$('#fax').val(ui.item.fax);
$('#taxBdy').val(ui.item.taxCode);
$('.tooltip').hide();
}
});
}
$('#mca').live("keydown",function(i) { if(!numbersAndDecimals(i)){return false;}else{return true;} });
$('#menuButton').click(function() { window.location = 'EMMENU'; });
});
</script>
<style type="text/css">
td.DataTD {text-align:left;}
.ui-autocomplete { text-align:left; width:250px; overflow:auto; height:200px;}
.tooltip { z-index:950; background-color:#000; border:1px solid #fff; padding:10px 15px; width:200px; display:none; color:#fff; text-align:left; font-size:12px; -moz-box-shadow:0 0 10px #000; -webkit-box-shadow:0 0 10px #000; }
</style>
</head>
<body>
<div class="container">
<div class="ui-widget-header ui-corner-all title">Customers</div><br />
<div class="navigation">
<button id="menuButton">Menu</button>
<button id="addButton">Add</button>
<button id="editButton">Edit</button>
<button id="deleteButton">Delete</button>
</div><br />
<table id="custGrid"></table> <div id="custPager" ></div><br />
</div>
</body>
</html>
Any ideas?
23:06

05/02/2009

Found it! I needed to have a return[true]; in the beforeSubmit of the add new customer section. Finished product looks like...
...beforeSubmit: function(){
var city = $('#city').val();
var state = $('#state').val();
var zip = $('#zip').val();
valCityStateZip(city,state,zip);
$('.tooltip').hide();
return[true];
}
Most Users Ever Online: 715
Currently Online:
69 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66