-- Auth-page form helpers. Used by the shared password_form.html.jinja2.

-- Cross-field native HTML5 validity for the password/confirm pair.
-- Installed on the form element via data-script="install passwordMatchValidation".
-- The browser shows its native validation tooltip on submit if the values
-- diverge — no toast involvement, no client-side message rendering.
behavior passwordMatchValidation
  on input from <input[name="new_password"], input[name="confirm_password"]/> in me
    set newEl to the first <input[name="new_password"]/> in me
    set confirmEl to the first <input[name="confirm_password"]/> in me
    if no newEl or no confirmEl then exit end
    if newEl's value is confirmEl's value
      call confirmEl.setCustomValidity('')
    else
      call confirmEl.setCustomValidity('Passwords do not match')
    end
  end
end
