Forum: Ruby on Rails Sending form data with link_to_remote

Ff43001ac5fe9805aa6ca2e89d3b7b5d?d=identicon&s=25 Jake Janovetz (janovetz)
on 2007-02-15 19:06
I have a form with several text_fields that is submitted with a standard
"submit" button.

With one of the text_fields, however, I'd like to have a "Test This"
link next to it that will submit the text field entry and perform a
simple test at the server.  The server will then respond with some RJS
to indicate pass/fail status.

I can use "observe_field" to do this automatically on the field data,
but I'd rather have a separate link to do this.

Since this is part of a bigger form, I don't think I can use another
form_remote nested within.

Is there a handy way to create such a thing?
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-02-15 19:19
(Received via mailing list)
Jake Janovetz wrote:

>
> Since this is part of a bigger form, I don't think I can use another
> form_remote nested within.

That might be the notorious 'with FAQ', which I myself have asked.

Send the link_to_remote using :with => 'Form.serialize("my_form")',
IIRC.

That converts the form's current values into GET parameters.

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand  <-- NOT a blog!!
B09a3f6cdc4797532647d2d264b5df49?d=identicon&s=25 Jodi Showers (jshow)
on 2007-02-15 19:29
(Received via mailing list)
On 15-Feb-07, at 1:18 PM, Phlip wrote:

>> RJS
> Send the link_to_remote using :with => 'Form.serialize("my_form")',
> IIRC.
>
> That converts the form's current values into GET parameters.

or if you don't want to sent the entire serialized form, you can use
the following js method:

function serialize_form_elements(form_elements_array) {
   var queryComponents = new Array();

   for (var i = 0; i < form_elements_array.length; i++) {
     var queryComponent = Form.Element.serialize(form_elements_array
[i]);
     if (queryComponent)
       queryComponents.push(queryComponent);
     }
     return(queryComponents.join('&'));
}

usage:

    get_query_string = serialize_form_elements([$('form_element_1'), $
('form_element_2')); #you can probably just pass an array of element
id's

and then plug that into like_to_remote with ':with' as Phillip said.

note: relies upon prototype's Form.Element.serialize smarts.

Cheers,
Jodi
General Partner
The nNovation Group inc.
www.nnovation.ca/blog
Ff43001ac5fe9805aa6ca2e89d3b7b5d?d=identicon&s=25 Jake Janovetz (janovetz)
on 2007-02-15 19:32
Thanks, Jodi, Philip--

I was having some trouble with some code I found.  I'm using this:

:with => "'bucket='+$('crummy').value"

and it seems to work just peachy!

   Cheers,
   Jake
B09a3f6cdc4797532647d2d264b5df49?d=identicon&s=25 Jodi Showers (jshow)
on 2007-02-15 19:38
(Received via mailing list)
On 15-Feb-07, at 1:32 PM, Jake Janovetz wrote:

>
> Thanks, Jodi, Philip--
>
> I was having some trouble with some code I found.  I'm using this:
>
> :with => "'bucket='+$('crummy').value"
>
> and it seems to work just peachy!

that'll work just find until you try that trick with checkboxes,
radiobuttons, selects. That's when you want to serialize

Cheers,
Jodi
General Partner
The nNovation Group inc.
www.nnovation.ca/blog
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-02-15 19:48
(Received via mailing list)
Jodi Showers wrote:

> > :with => "'bucket='+$('crummy').value"
> >
> > and it seems to work just peachy!
>
> that'll work just find until you try that trick with checkboxes,
> radiobuttons, selects. That's when you want to serialize

Thanks! The only reason I could think not to do that is a general
reticence against deeply nested inescapable quotes and delimiters. As
a rule of thumb...

And I think Form.serialize calls a Form.Element.serialize, or
something, that's accessible...

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand  <-- NOT a blog!!
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.