HubSpot / vex

A modern dialog library which is highly configurable and easy to style. #hubspot-open-source
http://github.hubspot.com/vex/docs/welcome
MIT License
6.92k stars 491 forks source link

cannot use <label for="unique-id"> becuse html is cloned #252

Open GeKVe opened 6 years ago

GeKVe commented 6 years ago

because the nature of vex.open() is to clone content passed in unsafeContent, one cannot use content placed in DOM by template engines. an option for remove+restore original would be one way to fix it

in this (pseudo-code) example <label> elements does not work:

<html><body>
  <div class="hidden-form-html" style="display:none;">
    <form>
      <input id="unique-input-id"/ type="checkbox" name="confirmed" value="1">
      <label for="unique-input-id">Click here to confirm</label>
    </form>
  </div>
</body></html>

<script>
  var html = $('.hidden-form-html').html();
  // Open form in a popup
  vex.open({
    unsafeContent: html,
    afterOpen: function() {
      initForm(this.contentEl);
    }
  });

  var initForm = function(formWrapper) {
    // code for form validation + submit here
  }
</script>