Ruby on Rails Sunday, April 2, 2017

> On Apr 2, 2017, at 10:55 AM, fugee ohu <fugee279@gmail.com> wrote:
>
> The reason it didn't work is because rails actionview radio button helper creates radio buttons which successfully relay info on form submission but actually the html it renders leaves out a foward slash for the closing greater than sign > should be /> so it causes jquery not to pick it up properly; maybe, that's how i fixed it i think


Rails since v3 has used HTML5 for its templating language by default. If you haven't changed anything, that's the expectation. HTML5 allows but does not require the "self-closed" tags of XHTML -- <hr /> and <hr> are equivalent, IOW.

In my (admittedly limited) experience with jQuery (I have far more experience with Prototype), I doubt very much that the trailing slash had anything to do with the matcher. Both Prototype and jQuery use the Sizzle matcher, and it's extremely good. More likely, you may have inadvertently written invalid HTML (regardless of level) including multiple items with the same ID attribute. It's always a good first step when diagnosing JavaScript weirdness to view source in a browser, copy it, and paste it into https://validator.w3.org to see if there are any obvious errors. jQuery won't complain if you use the same ID twice (or more) in a page, but it will do unpredictable things when you try to access an attribute or value.

Finally, the Rails checkbox / radio button helper provides an empty same-name hidden variable for each item that needs one, since in all HTML/CGI interfaces, the lack of a checkbox does not send a foo=false in a form post, it just does not send foo at all. Thus you will see this construction in your radio buttons:

<input type="hidden" name="foo" value="" />
<input type="radio" name="foo" value="bar" />
<input type="radio" name="foo" value="baz" />

This means that the foo key will be present in all of your submissions, regardless if any of the options are checked or not. This is of much more importance in checkboxes than radio buttons, since without it, there would be no way to "un-check" a checkbox using an HTML form.

Walter

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0123F25C-003D-4883-A63A-3123026CB71F%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment