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? soichi
on 2013-02-13 08:27
on 2013-02-13 14:43
On Feb 13, 2013, at 2:27 AM, Soichi Ishida wrote: > > 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
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.