Hello All ! I''ve been using RJS extensively, but haven''t done any form validation with it until now. Should I be manually passing the RJS template some models error messages from the controller.... or ... should I be using error_messages_for in order to do the display ? I''ve implemented the first approach, but it seems like quite a hack. Any insight would be greatly appreciated ! Thanks ! =Dylan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060323/1a18bcae/attachment.html
I do it the same as with non-ajax forms, just throw your <%error_messages_for :model %> at the top of a form partial If there''s an error creating, or updating the model, just page.replace_html''id_of_el_surrounding_form_partial'', :partial => ''form'' That way you still get highlighting for the failed fields, and it makes it easy to provide a fallback if javascript is disabled. joshua On 3/23/06, Dylan Stamat <dylans@gmail.com> wrote:> > Hello All ! > > I''ve been using RJS extensively, but haven''t done any form validation with > it until now. > > Should I be manually passing the RJS template some models error messages > from the controller.... or > ... should I be using error_messages_for in order to do the display ? > > I''ve implemented the first approach, but it seems like quite a hack. > Any insight would be greatly appreciated ! > Thanks ! > => Dylan > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060323/e3707e9d/attachment.html
Thanks Joshua, this works perfectly. In my case, the :partial is actually a component... and... haven''t checked if RJS supports :component.... hmmm... I''m lazy :) On 3/23/06, Joshua Bates <joshuabates@gmail.com> wrote:> > I do it the same as with non-ajax forms, just throw your <%> error_messages_for :model %> at the top of a form partial > If there''s an error creating, or updating the model, just > page.replace_html ''id_of_el_surrounding_form_partial'', :partial => ''form'' > That way you still get highlighting for the failed fields, and it makes it > easy to provide a fallback if javascript is disabled. > > joshua > > On 3/23/06, Dylan Stamat <dylans@gmail.com> wrote: > > > Hello All ! > > I''ve been using RJS extensively, but haven''t done any form validation with > it until now. > > Should I be manually passing the RJS template some models error messages > from the controller.... or > ... should I be using error_messages_for in order to do the display ? > > I''ve implemented the first approach, but it seems like quite a hack. > Any insight would be greatly appreciated ! > Thanks ! > => Dylan > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060324/9a502f33/attachment.html
I have a feeling RJS won''t support components, and even if it did I would avoid using them. Check out http://railsexpress.de/blog/articles/2005/11/18/components-may-not-be-evil-but-they-sure-can-be-slow You want those ajax calls to be snappy! joshua On 3/24/06, Dylan Stamat <dylans@gmail.com> wrote:> > Thanks Joshua, this works perfectly. > In my case, the :partial is actually a component... and... haven''t checked > if RJS supports :component.... hmmm... I''m lazy :) > > > > > On 3/23/06, Joshua Bates <joshuabates@gmail.com> wrote: > > > > I do it the same as with non-ajax forms, just throw your <%> > error_messages_for :model %> at the top of a form partial > > If there''s an error creating, or updating the model, just > > page.replace_html ''id_of_el_surrounding_form_partial'', :partial => > > ''form'' > > That way you still get highlighting for the failed fields, and it makes > > it easy to provide a fallback if javascript is disabled. > > > > joshua > > > > On 3/23/06, Dylan Stamat <dylans@gmail.com> wrote: > > > > > Hello All ! > > > > I''ve been using RJS extensively, but haven''t done any form validation > > with it until now. > > > > Should I be manually passing the RJS template some models error messages > > from the controller.... or > > ... should I be using error_messages_for in order to do the display ? > > > > I''ve implemented the first approach, but it seems like quite a hack. > > Any insight would be greatly appreciated ! > > Thanks ! > > => > Dylan > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060324/4749cba9/attachment.html
Hi Dylan, I added a <div id="flash_box" style="display: none"> </div> just ahead of my form_remote_to tag helper. Then in the action method of the form (create.rjs in my case: if @client.errors.length > 0 page.replace_html ''flash_box'', error_messages_for(:client) page.show ''flash_box'' else page.hide ''flash_box'' end I got the hint from liquid''s comment to http://rails.techno-weenie.net/question/2006/2/23/ajax_validation_flash_messages_redirects Ed On 3/23/06, Dylan Stamat <dylans@gmail.com> wrote:> Hello All ! > > I''ve been using RJS extensively, but haven''t done any form validation with > it until now. > > Should I be manually passing the RJS template some models error messages > from the controller.... or > ... should I be using error_messages_for in order to do the display ? > > I''ve implemented the first approach, but it seems like quite a hack. > Any insight would be greatly appreciated ! > Thanks ! > => Dylan > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Ed Howland http://greenprogrammer.blogspot.com