@startinblox/core 0.19.18 → 0.19.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +60 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -50939,9 +50939,69 @@ const RichtextMixin = {
|
|
|
50939
50939
|
}
|
|
50940
50940
|
const ops = deltaMd.toDelta(this.value);
|
|
50941
50941
|
this.quill.setContents(ops);
|
|
50942
|
+
if (this.isRequired()) {
|
|
50943
|
+
this.createHiddenRequiredInput();
|
|
50944
|
+
this.quill.on("text-change", this.onTextChange.bind(this));
|
|
50945
|
+
}
|
|
50942
50946
|
const nextProcessor = listCallbacks.shift();
|
|
50943
50947
|
if (nextProcessor)
|
|
50944
50948
|
nextProcessor(value, listCallbacks);
|
|
50949
|
+
},
|
|
50950
|
+
isRequired() {
|
|
50951
|
+
return Array.from(this.element.attributes).some((attr) => attr.name === "required");
|
|
50952
|
+
},
|
|
50953
|
+
createHiddenRequiredInput() {
|
|
50954
|
+
const attributeName = this.getAttributeValue("name");
|
|
50955
|
+
this.hiddenInput = document.querySelector(`input[name="${attributeName + "-hidden"}"]`);
|
|
50956
|
+
if (!this.hiddenInput) {
|
|
50957
|
+
this.hiddenInput = this.createHiddenInput(attributeName + "-hidden");
|
|
50958
|
+
this.element.appendChild(this.hiddenInput);
|
|
50959
|
+
this.addInvalidEventListener();
|
|
50960
|
+
}
|
|
50961
|
+
this.hiddenInput.value = this.quill.getText();
|
|
50962
|
+
},
|
|
50963
|
+
createHiddenInput(attributeName) {
|
|
50964
|
+
const input = document.createElement("input");
|
|
50965
|
+
input.name = attributeName;
|
|
50966
|
+
input.setAttribute("required", "true");
|
|
50967
|
+
input.style.opacity = "0";
|
|
50968
|
+
input.style.position = "absolute";
|
|
50969
|
+
input.style.pointerEvents = "none";
|
|
50970
|
+
return input;
|
|
50971
|
+
},
|
|
50972
|
+
getAttributeValue(attributeName) {
|
|
50973
|
+
const attribute2 = Array.from(this.element.attributes).find((attr) => attr.name === attributeName);
|
|
50974
|
+
return attribute2 ? attribute2.value : "";
|
|
50975
|
+
},
|
|
50976
|
+
displayCustomErrorMessage(message) {
|
|
50977
|
+
const richtext = this.element.querySelector("[data-richtext]");
|
|
50978
|
+
if (richtext) {
|
|
50979
|
+
let errorMessageElement = richtext.querySelector(".required-error-message");
|
|
50980
|
+
if (!errorMessageElement) {
|
|
50981
|
+
errorMessageElement = document.createElement("div");
|
|
50982
|
+
errorMessageElement.className = "required-error-message";
|
|
50983
|
+
}
|
|
50984
|
+
richtext.appendChild(errorMessageElement);
|
|
50985
|
+
errorMessageElement.textContent = message;
|
|
50986
|
+
richtext.classList.add("error-border-richtext");
|
|
50987
|
+
}
|
|
50988
|
+
},
|
|
50989
|
+
addInvalidEventListener() {
|
|
50990
|
+
this.hiddenInput.addEventListener("invalid", (e) => {
|
|
50991
|
+
e.preventDefault();
|
|
50992
|
+
this.displayCustomErrorMessage("Please fill out this field.");
|
|
50993
|
+
});
|
|
50994
|
+
},
|
|
50995
|
+
onTextChange() {
|
|
50996
|
+
this.hiddenInput.value = this.quill.getText();
|
|
50997
|
+
this.removeErrorMessageAndStyling();
|
|
50998
|
+
},
|
|
50999
|
+
removeErrorMessageAndStyling() {
|
|
51000
|
+
const richtext = this.element.querySelector("[data-richtext]");
|
|
51001
|
+
let errorMessageElement = richtext.querySelector(".required-error-message");
|
|
51002
|
+
if (errorMessageElement)
|
|
51003
|
+
errorMessageElement.remove();
|
|
51004
|
+
richtext.classList.remove("error-border-richtext");
|
|
50945
51005
|
}
|
|
50946
51006
|
};
|
|
50947
51007
|
const callbackDirectory = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startinblox/core",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.19",
|
|
4
4
|
"description": "This is a series of web component respecting both the web components standards and the Linked Data Platform convention.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|