Forum


21:13

20/03/2009

Hi,
I'm building a quick time validation (ie the end time for a task must be great than the start time)
I can create an event for the time boxes losing focus to alert via an alert message but I would prefer the message to come up when the submit button is clicked.
I've tried using the beforesubmit event and I can get the id's of the select boxes but never the text associated with the value. I'm trying as follows:
beforeSubmit:function(pdata){
//Note: pdata is changed to form_id to try the two lines below
//d1 = $("select#START :selected",form_id).text();
//d2 = $("select#FINISH :selected",form_id).text();
var d1 = pdata["START"];
var d2 = pdata["FINISH"];
alert("t_0 - " + d1);
alert("t_1 - " + d2);
}
Is there a means of grabbing the text value ? The commented lines are how I got the text values in the lost focus but it seems like pdata is just an array of the id's of select boxes?
Nathan
03:57

Moderators
30/10/2007

Hello,
Yes this is true. The post array contain the key, but not the text.
If you want to post the text use onclickSubmit event (see docs) with your code above. This event should return array. It is a good idea to give other names of the posted data.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
21:47

20/03/2009

Hi Tony,
I am not to clear on this method. I've reviewed the documentation but I am still struggling.
What I want to do is grab the two values, Start, Finish which are select boxes. I want to compare them to ensure that finish is greater than start. If its not I want to push a message back to the edit form saying "Please correct time entries" and not post the data to the server. Essentially cancel the submit event if the times are incorrect. I can't seem to get the values and I am a little unclear on the documentation example(eparams). How is this variable set up for referencing array elements. Reviewing eparams in firebug did not indcate any values for any of the form controls. Just a little confused here.
onclickSubmit:function(pdata){
var retarray = {};
var d1 = pdata["START"];
var d2 = pdata["FINISH"];
alert("t_0 - " + d1);
alert("t_1 - " + d2);
return retarray;
}
_______
My alternate solution would be to do this in the php file. I can compare the times passed in the param array and if there is an error push a message back to the form and not call the database update. But how do I push an error message back from the php file to the form?
Nathan
10:48

Moderators
30/10/2007

Hello,
Why not use afterSubmit event - it is designed right for this purpose (If I understand right)
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
19:30

20/03/2009

Hi Tony,
The afterSubmit works but I am little unclear on how to handle the cancellation part. I've got
if (xhr.responseText=="Time Error!"){
alert("Please correct your time entries");
//jQuery('#hours').trigger("reloadGrid");
return false;
}else{
return true;
}
My php file returns "Time Error!" correctly and does not actually add the information to the database - but the data is added to the grid. If I click refresh it's gone from the grid. How do I not have the grid not reflect the data until it's corrected.
Also, right now I'm just using an alert box. Is there a means of using the error portion of the form ie. where it says "field required". How would I change that to indicate "Please correct the times"
Thanks for all your help!
Nathan
Most Users Ever Online: 715
Currently Online:
45 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