ga-wdi-boston / capstone-project

Other
3 stars 28 forks source link

Launching modal from click event and autofilling properties #687

Closed eliottenos closed 7 years ago

eliottenos commented 7 years ago

Im trying to launch my modal upon click event on map. I've got a function that launches an alert which passes in data for country from the library but I'm trying to launch a modal which autofills same data in 'country' field. This is my function that generates alert

<script>
    const map = new Datamap({
        element: document.getElementById('container'),
        done: function(datamap) {
            datamap.svg.selectAll('.datamaps-subunit').on('click', function(geography) {
                alert(geography.properties.name);
            });
        }
    });
</script>

and this is my modal

<div class="modal fade" id="mapModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="mapModalLabel">New Country</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="recipient-name" class="form-control-label">Country:</label>
            <input type="text" class="form-control" id="recipient-name">
          </div>
          <div class="form-group">
            <label for="message-text" class="form-control-label">Note:</label>
            <textarea class="form-control" id="message-text"></textarea>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Send message</button>
      </div>
    </div>
  </div>
</div>

any idea how to launch modal instead and pass in data?

MicFin commented 7 years ago
  1. Your modal needs to be a handlebars template that you pass the data to
  2. Then add the modal template to the DOM
  3. Then trigger the modal