Skip to content

Prefer matching fragments within a given { origin } #197

Description

@boxxxie

Bug description

discovered this when my forms were set to target an inner element, but instead the first matching element on the page was selected (this is a page with a list of forms)

<div>
    <div class="auto-submit d-flex"></div>
    <form
      {% if id %}id="{{id}}"{% else %}id="form_{{name}}"{% endif %}
      up-transition="cross-fade"
      up-target=".auto-submit"
      up-method="{{up-method|default:PATCH}}"
      up-autosubmit
      up-delay="{{up-delay|default:1000}}"
      enctype="multipart/form-data"
      up-history="false"
      action="{{action}}">
        {% block component %}{% endblock %}
        <div class="auto-submit d-flex"> </div>
    </form>
</div>

response

<div class="auto-submit d-flex">
    <img src="/assets/Font-Awesome/svgs/solid/check-circle.svg">
    <p>Profile Upadted !</p>
</div>

my workaround/fix

var selector_closest_fixed = false;
(function fix_selector_closest(){
  if(!selector_closest_fixed){
    selector_closest_fixed = true
    up.Selector.prototype.closest = function(element) {
      var parentElement;
      let child_target = element.querySelector(this.unionSelector);
      if (child_target){
        return child_target
      }
      else if (this.matches(element)) {
        return element;
      } else if ((parentElement = element.parentElement)) {
        return this.closest(parentElement);
      }
    };
  }
})();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions