Jeremy Cowgar
2006-Jul-20 12:46 UTC
[Rails] AJAX Form, :postion => :bottom but replace when error?
I have a form below a table to add new notes to an item. If the note does not have a title or body, the note is not saved and a form error is displayed. However, if the note validates successfully, then the note is added to the bottom of the table above. Just for reference, the table id is "note_list" and the add form div is id="note_add_form". So, my problem/question is. Upon success, I want to update note_list appending to the bottom of the table, however, upon failure, I want to replace note_list *not* append to the bottom of it. I can do something like this: :update => { :success => ''note_list'', :failure => ''note_add_form''}, :position => :bottom on my form tag and that works partially. When a note is added successfully, it''s appended to the bottom of the table. However, when a validation error occurs, the error message and a whole new form is appended to the bottom of the existing form. If I fail again, the note_add_form div will then have three forms, etc... Is there a way to make this work? Jeremy Cowgar
Bryan Tec
2006-Jul-20 13:18 UTC
[Rails] AJAX Form, :postion => :bottom but replace when error?
Jeremy, If you have a container div (or other structure) for note_add_form you can use rjs and something like: page.replace ''container_div_id'', ''html the you want to replace with (i.e. <div id=''list_fail''>You broked it!</div>)'' Bryan On 7/20/06, Jeremy Cowgar <jeremy@cowgar.com> wrote:> > I have a form below a table to add new notes to an item. If the note > does not have a title or body, the note is not saved and a form error > is displayed. However, if the note validates successfully, then the > note is added to the bottom of the table above. Just for reference, > the table id is "note_list" and the add form div is id="note_add_form". > > So, my problem/question is. Upon success, I want to update note_list > appending to the bottom of the table, however, upon failure, I want > to replace note_list *not* append to the bottom of it. > > I can do something like this: > > :update => { :success => ''note_list'', :failure => > ''note_add_form''}, :position => :bottom > > on my form tag and that works partially. When a note is added > successfully, it''s appended to the bottom of the table. However, when > a validation error occurs, the error message and a whole new form is > appended to the bottom of the existing form. If I fail again, the > note_add_form div will then have three forms, etc... > > Is there a way to make this work? > > Jeremy Cowgar > > _______________________________________________ > 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/20060720/70a3638d/attachment-0001.html
Jeremy Cowgar
2006-Jul-20 14:48 UTC
[Rails] AJAX Form, :postion => :bottom but replace when error?
What if the content I want to place it with is the rendered template? For instance: <%= error_messages_for ''note'' %> Jeremy On Jul 20, 2006, at 9:18 AM, Bryan Tec wrote:> Jeremy, > > If you have a container div (or other structure) for note_add_form > you can use rjs and something like: > > page.replace ''container_div_id'', ''html the you want to replace with > (i.e. <div id=''list_fail''>You broked it!</div>)'' > > > Bryan > > > On 7/20/06, Jeremy Cowgar <jeremy@cowgar.com> wrote: > I have a form below a table to add new notes to an item. If the note > does not have a title or body, the note is not saved and a form error > is displayed. However, if the note validates successfully, then the > note is added to the bottom of the table above. Just for reference, > the table id is "note_list" and the add form div is > id="note_add_form". > > So, my problem/question is. Upon success, I want to update note_list > appending to the bottom of the table, however, upon failure, I want > to replace note_list *not* append to the bottom of it. > > I can do something like this: > > :update => { :success => ''note_list'', :failure => > ''note_add_form''}, :position => :bottom > > on my form tag and that works partially. When a note is added > successfully, it''s appended to the bottom of the table. However, when > a validation error occurs, the error message and a whole new form is > appended to the bottom of the existing form. If I fail again, the > note_add_form div will then have three forms, etc... > > Is there a way to make this work? > > Jeremy Cowgar > > _______________________________________________ > 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/20060720/3c7a485e/attachment.html
Matt Broderick
2006-Jul-20 15:44 UTC
[Rails] Re: AJAX Form, :postion => :bottom but replace when error?
Jeremy Cowgar wrote:> What if the content I want to place it with is the rendered template? > For instance: > > <%= error_messages_for ''note'' %> > > JeremyPut that in its own div? -Matt -- Posted via http://www.ruby-forum.com/.