On Feb 13, 2013, at 2:27 AM, Soichi Ishida wrote: > Rails 3.2.11 > > When users click a "submit" button, the app can show a confirm dialog by > adding > > :confirm => "Are you sure?" > > I need to let it appear if certain conditions are met. It does not > appear if the conditions are not met although the submit action would > get executed. > > Say, I have a checkbox, then some JavaScript function detects if the > checkbox is checked or not. > Then, when users decide to click the submit button, the javascript > function sees if the checkbox status: the dialog appears if checked and > submit action follows as users confirm it. The dialog does not appear > but submit action gets executed without confirmation. > > Could anyone give me some ideas how to implement something described?
Sure. Set up two buttons on a scratch form page, look at the output in a browser, and note the differences between them. (Depending on the version of Rails you are using, it will be something like data-confirm="Are you sure?" or it might be a blodge of inline JavaScript hooked to the click event.) What you'll need to do -- in JavaScript -- is observe the form for changes, and programmatically add that property or listener depending on the current state of the form. In Prototype, I would use the Form.Observer method. I'm not sure what the equivalent is in jQuery, but I'm sure there's something like it. Walter > > soichi > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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+unsubscr...@googlegroups.com. > To post to this group, send email to rubyonrails-talk@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.