modal dialog box

16 views
Skip to first unread message

Joe Guerra

unread,
Oct 19, 2018, 9:14:43 AM10/19/18
to Ruby on Rails: Talk
HI, I'd like to insert a bootstrap modal dialog box between my add to cart button and the actual action.

I know how to display the dialog box, but not sure how to hook it up to the form cart button?  [and the actual saving to cart]

Any suggestions?
Thanks,
Joe

Walter Lee Davis

unread,
Oct 20, 2018, 8:13:08 AM10/20/18
to rubyonra...@googlegroups.com
Do you have multiple buttons on the page, each referring to a different product, and do you intend them to all go "through" a single modal? You're going to need to add some JavaScript to the mix, I imagine. Put a generic form in the modal itself, and then use data-attributes or a querystring to "tell" the modal which product is being ordered. You'll have to use JS to change the form element that signals what product is being ordered. Once you get through that, the rest is a normal CRUD Rails 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/cc801572-b58e-4408-8678-bab4f90dfdf9%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Joe Guerra

unread,
Oct 20, 2018, 2:28:58 PM10/20/18
to Ruby on Rails: Talk
No, I have an add to cart button, and I'd like them to confirm their action with a modal dialog box and if yes - save the record to the table, if no- do nothing.

[and I can also use the dialog to display some info].

Greg Navis

unread,
Oct 20, 2018, 2:58:25 PM10/20/18
to rubyonra...@googlegroups.com
You can pre-render the modal with a confirmation form. When clicking "Add to cart" you can update the form with the ID of the product being added and show the modal. When the user submits the form it'll send the right product ID to the server.

Best
Greg
Message has been deleted

Joe Guerra

unread,
Oct 23, 2018, 11:19:42 AM10/23/18
to Ruby on Rails: Talk





Capture.PNG


Ok, this is what I have so far.  I've added the bootstrap modal and put the button right next to the actual button.  So, I need to render this modal, and then on the modal boxes save changes (update the cart).  
oh, the other thing I couldn't figure out is how to get the :qty from the form input field.  I need to check this value compare it to the remaining as well.


Thanks,
Joe

Walter Lee Davis

unread,
Oct 23, 2018, 11:56:12 AM10/23/18
to rubyonra...@googlegroups.com
You could just make the regular button show a confirmation dialog in the usual Rails way

data: { confirm: "Are you sure you want to add #{@product.name} to your cart?" }

Then there are any number of Bootstrap plug-ins that hijack a normal JS confirm dialog (which is what the above creates) and style it as a BS modal. That way your form (including the quantity field) submits normally, and the Dootstrap part just decorates the result of a confirm() dialog in JS.

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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9326f448-1185-4afa-96c3-e475aa527751%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> <Capture.PNG>

Joe Guerra

unread,
Oct 23, 2018, 1:36:23 PM10/23/18
to rubyonra...@googlegroups.com
yes, that's what I ended up doing.  Removed the modal, and used the built-in submit tag confirmation.
It will have to do.

Reply all
Reply to author
Forward
0 new messages