Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do modal dialogs with Om or Reagent (and Bootstrap)

I wonder how showing and hiding of a modal dialog should be implemented with Om or Reagent. Since my UI is a function on the state, the show/hide should be triggered by a property in this state.

But frameworks like Bootstrap require to call some JavaScript to show/hide dialogs.

Is there any common solution for this problem?

like image 694
Witek Avatar asked Feb 29 '16 20:02

Witek


People also ask

How do I submit a Bootstrap modal form?

You CAN include a modal within a form. In the Bootstrap documentation it recommends the modal to be a "top level" element, but it still works within a form. You create a form, and then the modal "save" button will be a button of type="submit" to submit the form from within the modal.

How do I make a Bootstrap modal scrollable?

Bootstrap 4.3 added new built-in scroll feature to modals. This makes only the modal-body content scroll if the size of the content would otherwise make the page scroll. To use it, just add the class modal-dialog-scrollable to the same div that has the modal-dialog class. Save this answer.

What is the example of modal dialog box?

This dialog disables the main content until the user explicitly interacts with the modal dialog. A modal dialog is like my cat, Emma — who meows at 7am every morning to prompt me to feed her.

How can I show data using a modal when clicking a table row using Bootstrap?

On each of your <tr> 's add a data attribute for id (i.e. data-id ) with the corresponding id value and specify a data-target , which is a selector you specify, so that when clicked, bootstrap will select that element as modal dialog and show it.


2 Answers

Don't use javascript or jquery effects to show/hide dialogs in Om or Reagent. Instead, make the value of an atom determine whether the modal dialog should be shown. Here is an example for Reagent:

[(fn [shown]
       (if shown
        [:div.jumbotron.modal-background 
          {:on-click #(reset! popup-shown false)} 
          [:div.alert.alert-info
            [:div "Hello!"]]]
        [:div]))
   @popup-shown]
like image 180
Terje Norderhaug Avatar answered Jan 31 '23 17:01

Terje Norderhaug


Have a look at re-com. It certainly shows one way of doing it. https://github.com/Day8/re-com

like image 36
Mike Thompson Avatar answered Jan 31 '23 18:01

Mike Thompson