Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap - Editing TextArea Behind Modal

I have a web page that uses Bootstrap 3. In this page, I need to have a text area that a person can put their answer in. The answer is to a story problem. The story problem appears in a modal dialog. The setup can be seen in this Bootply. The code looks like this:

<div class="container">
  <form>
    <div class="form-group">
      <label>Answer (<a id="showProblemLink" href="#">view problem</a>)</label>
      <textarea class="form-control" rows="7">      </textarea>
    </div>
  </form>

  <div id="problemModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-body">
            <p>
            The local school wants a new playground.
            The lot they can use for the playground is shaped like a rectangle.
            The school has decided to let the students design the new playground.
            The students have decided that they want 1/4 of the playground to be a football field.
              Another 3/8 of the lot will be used for a basketball court.
              How much of the lot is remaining for the slides and swings?
            </p>
        </div>

        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>        
      </div>      
    </div>
  </div>  
</div>

My users want to be able to keep the story problem open in the modal window while they enter their answer. This will let them double-check their answer. The obvious answer is to have them re-open the dialog. But, apparently, this isn't good enough. I really need to keep the dialog open and let the user enter data in the text area behind/under it. Seems weird to me. But, that's what I gotta do.

My problem is, when I click on the textarea, the dialog disappears. I tried adding data-backdrop="false". While that kept dialog open, it didn't let me actually edit the textarea. What am I missing?

like image 950
user687554 Avatar asked Jan 24 '17 14:01

user687554


People also ask

What is backdrop in Bootstrap modal?

The backdrop option specifies whether the modal should have a dark overlay (the background color of the current page) or not.

How do I open modal on top of another modal?

To open a modal from another modal can be done simply by using the events that Bootstrap provides such as show. bs. modal . You may also want some CSS to handle the backdrop overlays.

How do I stop the background when modal windows pop up?

The key idea is to have pointer-events: none; for the body when modal is open. But the specific elements you want to be interacted with should have e.g. pointer-events: auto; . In the example you can click both buttons when dialog is hidden, but only Toggle Dialog button when dialog is shown.

How do you align modal content box to center of any screen?

Example 1: First, we will design modal content for the sign-up then by using CSS we will align that modal centered(vertically). Using the vertical-align property, the vertical-align property sets the vertical alignment of an element.


2 Answers

Actually it is very simple to get exactly what you want.

enter image description here

What you are actually looking for is a Dialog and not a Modal.

Here is a working example using jQuery UI Dialog.


Explanation:

  • A modal is designed to block user interaction with the application.
  • A dialog looks and acts similar, but is designed to let the user continue interacting with the page (You can set it manually to block everything if you want)

Here is a SO discussion about it


Some details about the example:

By default a dialog is draggable by the header. I kept the example similar to your modal so I took out the header by using:

dialogClass: 'dialog-modal'

And

.dialog-modal .ui-dialog-titlebar {
  display:none;
}

To make the whole dialog draggable I used:

draggable: false

And

.parent().draggable();

If you actually do want a header, you can delete all these parts. Here is an example with a header

like image 180
Jaqen H'ghar Avatar answered Nov 15 '22 03:11

Jaqen H'ghar


What you are trying to achieve is not easily possible.

  • Hiding modal background - easy
  • Moving whole modal div - medium
  • Making the text area behind the modal take the focus - very hard

I understand you want to save space on the page, that's why I would suggest the cleanest option and closest to what you are trying to achieve: Bootstrap Collapse

DEMO here

enter image description here

like image 42
SDekov Avatar answered Nov 15 '22 04:11

SDekov