Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI: .validationMessage assertion #1194

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/test/system/custom_element_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rangesAreEqual } from "trix/core/helpers"
import { makeElement, rangesAreEqual } from "trix/core/helpers"
import TrixEditorElement from "trix/elements/trix_editor_element"

import {
Expand Down Expand Up @@ -635,6 +635,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
testIf(TrixEditorElement.formAssociated, "validates with [required] attribute as invalid", () => {
const editor = document.getElementById("editor-with-ancestor-form")
const form = editor.form
const invalidInput = makeElement("input", { required: true })
let invalidEvent, submitEvent = null

editor.addEventListener("invalid", event => invalidEvent = event, { once: true })
Expand All @@ -646,7 +647,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
// assert.equal(document.activeElement, editor, "editor receives focus")
assert.equal(editor.required, true, ".required property retrurns true")
assert.equal(editor.validity.valid, false, "validity.valid is false")
assert.equal(editor.validationMessage, "Please fill out this field.", "sets .validationMessage")
assert.equal(editor.validationMessage, invalidInput.validationMessage, "sets .validationMessage")
assert.equal(invalidEvent.target, editor, "dispatches 'invalid' event on editor")
assert.equal(submitEvent, null, "does not dispatch a 'submit' event")
})
Expand Down
2 changes: 1 addition & 1 deletion src/trix/elements/trix_editor_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class ElementInternalsDelegate {
const { required, value } = this.element
const valueMissing = required && !value
const customError = !!customValidationMessage
const input = Object.assign(document.createElement("input"), { required })
const input = makeElement("input", { required })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorgemanrubia I'm not sure how to make sure it passes CI on main, but I do think this is worth merging on its own merits, since it re-uses an existing helper instead of an ad hoc combination of Object.assign and Document.createElement.

const validationMessage = customValidationMessage || input.validationMessage

this.#internals.setValidity({ valueMissing, customError }, validationMessage)
Expand Down
Loading