Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
beforesubmit and text value of a select box
31/03/2009
21:13
Avatar
Nathan
Member
Members
Forum Posts: 37
Member Since:
20/03/2009
sp_UserOfflineSmall Offline

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

01/04/2009
03:57
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

01/04/2009
21:47
Avatar
Nathan
Member
Members
Forum Posts: 37
Member Since:
20/03/2009
sp_UserOfflineSmall Offline

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

02/04/2009
10:48
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

03/04/2009
19:30
Avatar
Nathan
Member
Members
Forum Posts: 37
Member Since:
20/03/2009
sp_UserOfflineSmall Offline

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

03/04/2009
19:38
Avatar
Nathan
Member
Members
Forum Posts: 37
Member Since:
20/03/2009
sp_UserOfflineSmall Offline

Nevermind - fixed my own problem this time around 🙂

Turns out I never set reloadAfterSubmit:true to true ...

However, I still can't figure out if it's possible to post my response in the form.  Any suggestions on how to access that field to change it ?

Nathan

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information