[jQuery] serialize form

2007-03-14 Thread Dan Wilson
I am attempting to use the .serialize function to post a form via
Ajax. The form is very large and has just about every type of form
element possible. I was not clear on the semantics to select all form
elements in a particular form and all the examples I found were for
[EMAIL PROTECTED]

The use case is an autosave for the form. I looked at the form plugin
and it seemed to want to take control of the form submit. In my use
case I want to save the form in the background and let the user
continue to work with the form.


All help and advice is appreciated.

dw


-- 
Come to the edge, he said. They said: We are afraid. Come to the
edge, he said. They came. He pushed them and they flew.

 Guillaume Apollinaire quotes

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] serialize form

2007-03-14 Thread Mike Alsup
 The use case is an autosave for the form. I looked at the form plugin
 and it seemed to want to take control of the form submit. In my use
 case I want to save the form in the background and let the user
 continue to work with the form.

I would recommend using the form plugin.  Its primary function is to
provide ajax capabilities.  I'd be glad to help if you found it
confusing or if you have questions about it.

Mike

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] serialize form

2007-03-14 Thread Karl Swedberg


On Mar 14, 2007, at 11:40 AM, Mike Alsup wrote:


The use case is an autosave for the form. I looked at the form plugin
and it seemed to want to take control of the form submit. In my use
case I want to save the form in the background and let the user
continue to work with the form.


I would recommend using the form plugin.  Its primary function is to
provide ajax capabilities.  I'd be glad to help if you found it
confusing or if you have questions about it.


I second that recommendation! The form plugin makes ajax form  
submission astonishingly easy.


--Karl
_
Karl Swedberg
www.englishrules.com
www.learningjquery.com


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] serialize form

2007-03-14 Thread Klaus Hartl
Karl Swedberg schrieb:
 I second that recommendation! The form plugin makes ajax form submission 
 astonishingly easy.

I third that! It is so incredibly easy that I just wrote an enthusiastic 
email to Mike... :-)



-- Klaus

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] serialize form

2007-03-14 Thread Jack Killpatrick
Whoops, let out a piece: this will reset the timer after success, so the 
autosave will happen again:

function handleResponse(responseText, statusText)
{
startTimer();
}

If you pass a successFn into save(), then run startTimer() in that 
success function, so that the timer restarts after the successful autosave.

- Jack

Jack Killpatrick wrote:
 Dan,

 I'm using the form plugin to do an autosave. Here are some chunks of 
 what I do (it's not namespaced, so you might want to add that, etc):

 var _timerRunning = false;
 var _timer = null;

 function startTimer()
 {
if (! _timerRunning)
{
_timer = setTimeout ( save(), 12000 );
_timerRunning = true;
}
 }

 $(document).ready(function() {
startTimer();
 });

 function save(successFn)
 {
var options = {
type:   'POST',
beforeSubmit:   beginRequest,
success:   (successFn != undefined) ? successFn : 
 handleResponse,
semantic: true
};

$(#surveyForm).ajaxSubmit(options);
 }

 You can optionally pass success/callback function into save(), ie: 
 save( onSuccess ). In my case, it was OK for it to post to the url 
 declared in the form tag, but there's a url option you can set in the 
 form plugin, too. Not shown above: I also have a hidden name=action 
 element that I change the value of at different times, based on button 
 clicks (if the user causes a save), to support different handling on 
 the post to the server.

 - Jack

 Dan Wilson wrote:
 I am attempting to use the .serialize function to post a form via
 Ajax. The form is very large and has just about every type of form
 element possible. I was not clear on the semantics to select all form
 elements in a particular form and all the examples I found were for
 [EMAIL PROTECTED]

 The use case is an autosave for the form. I looked at the form plugin
 and it seemed to want to take control of the form submit. In my use
 case I want to save the form in the background and let the user
 continue to work with the form.


 All help and advice is appreciated.

 dw


   


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] serialize form

2007-03-14 Thread Jack Killpatrick
Dan,

I'm using the form plugin to do an autosave. Here are some chunks of 
what I do (it's not namespaced, so you might want to add that, etc):

var _timerRunning = false;
var _timer = null;

function startTimer()
{
if (! _timerRunning)
{
_timer = setTimeout ( save(), 12000 );
_timerRunning = true;
}
}

$(document).ready(function() {
startTimer();
});

function save(successFn)
{
var options = {
type:   'POST',
beforeSubmit:   beginRequest,
success:   (successFn != undefined) ? successFn : 
handleResponse,
semantic: true
};

$(#surveyForm).ajaxSubmit(options);
}

You can optionally pass success/callback function into save(), ie: save( 
onSuccess ). In my case, it was OK for it to post to the url declared in 
the form tag, but there's a url option you can set in the form plugin, 
too. Not shown above: I also have a hidden name=action element that I 
change the value of at different times, based on button clicks (if the 
user causes a save), to support different handling on the post to the 
server.

- Jack

Dan Wilson wrote:
 I am attempting to use the .serialize function to post a form via
 Ajax. The form is very large and has just about every type of form
 element possible. I was not clear on the semantics to select all form
 elements in a particular form and all the examples I found were for
 [EMAIL PROTECTED]

 The use case is an autosave for the form. I looked at the form plugin
 and it seemed to want to take control of the form submit. In my use
 case I want to save the form in the background and let the user
 continue to work with the form.


 All help and advice is appreciated.

 dw


   

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] serialize form

2007-03-14 Thread Jack Killpatrick
oof..left another little piece out of my original posting (so much for 
accurately snippetizing this thing, he he):

function beginRequest(formData, jqForm)
{
stopTimer();
}

FYI, I also have a little message appearing onscreen during the 
autosave: on success it disappears. That creates a sort of pulse that 
the users sees that tells them that the autosave is happening. From what 
I've been told, that gives them a nice comfortable feeling (that their 
stuff is being saved).

- Jack

Jack Killpatrick wrote:
 Whoops, let out a piece: this will reset the timer after success, so 
 the autosave will happen again:

 function handleResponse(responseText, statusText)
 {
startTimer();
 }

 If you pass a successFn into save(), then run startTimer() in that 
 success function, so that the timer restarts after the successful 
 autosave.

 - Jack

 Jack Killpatrick wrote:
 Dan,

 I'm using the form plugin to do an autosave. Here are some chunks of 
 what I do (it's not namespaced, so you might want to add that, etc):

 var _timerRunning = false;
 var _timer = null;

 function startTimer()
 {
if (! _timerRunning)
{
_timer = setTimeout ( save(), 12000 );
_timerRunning = true;
}
 }

 $(document).ready(function() {
startTimer();
 });

 function save(successFn)
 {
var options = {
type:   'POST',
beforeSubmit:   beginRequest,
success:   (successFn != undefined) ? successFn : 
 handleResponse,
semantic: true
};

$(#surveyForm).ajaxSubmit(options);
 }

 You can optionally pass success/callback function into save(), ie: 
 save( onSuccess ). In my case, it was OK for it to post to the url 
 declared in the form tag, but there's a url option you can set in the 
 form plugin, too. Not shown above: I also have a hidden name=action 
 element that I change the value of at different times, based on 
 button clicks (if the user causes a save), to support different 
 handling on the post to the server.

 - Jack

 Dan Wilson wrote:
 I am attempting to use the .serialize function to post a form via
 Ajax. The form is very large and has just about every type of form
 element possible. I was not clear on the semantics to select all form
 elements in a particular form and all the examples I found were for
 [EMAIL PROTECTED]

 The use case is an autosave for the form. I looked at the form plugin
 and it seemed to want to take control of the form submit. In my use
 case I want to save the form in the background and let the user
 continue to work with the form.


 All help and advice is appreciated.

 dw


   



___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] serialize form

2007-03-14 Thread Daemach

I wrote an autosave plugin a while back that automates autosaving fields.  It
doesn't submit the form at one time - instead it updates each field
immediately if they are changed.  I can find somewhere to post it if you
want to play with it.  

It gets called like the snippet below - I use ajaxCFC for ajax, but
$.post/$.get should work too.  When you use this in the function call it
refers to the element itself.  In editing forms I give my field ID's the
name dbfieldname_primarykeyID to make them easy to reference.  You could
also do tablename_fieldname_id if you really wanted to generalize the
backend function :)

$('input:[EMAIL PROTECTED]').each( function() {
$(this).autoSave(function(){
$.AjaxCFC({
url: /active/admin/cfc/seminars.cfc, 
method: updateAttendee, 
data: { field:this.id.split(_)[0],
id:this.id.split(_)[1],
value:this.value}, 
success: function(){}
});
});
});

Let me know if you're interested.


Dan Wilson wrote:
 
 I am attempting to use the .serialize function to post a form via
 Ajax. The form is very large and has just about every type of form
 element possible. I was not clear on the semantics to select all form
 elements in a particular form and all the examples I found were for
 [EMAIL PROTECTED]
 
 The use case is an autosave for the form. I looked at the form plugin
 and it seemed to want to take control of the form submit. In my use
 case I want to save the form in the background and let the user
 continue to work with the form.
 
 
 All help and advice is appreciated.
 
 dw
 
 
 -- 
 Come to the edge, he said. They said: We are afraid. Come to the
 edge, he said. They came. He pushed them and they flew.
 
  Guillaume Apollinaire quotes
 
 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/
 
 

-- 
View this message in context: 
http://www.nabble.com/serialize-form-tf3402789.html#a9480981
Sent from the JQuery mailing list archive at Nabble.com.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/