Skip to content

Commit

Permalink
Merge pull request #60 from WebCoder49/disabled-attribute
Browse files Browse the repository at this point in the history
Fix HTML attribute synchronisation
  • Loading branch information
WebCoder49 committed Oct 7, 2023
2 parents 0242a75 + ed6b156 commit 234d4ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
47 changes: 21 additions & 26 deletions code-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,28 @@ var codeInput = {
textareaSyncAttributes: [
"aria-*",
"value",
"name",
// Form validation - https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation#using_built-in_form_validation
"required",
"minlength", "maxlength",
"min", "max",
"type",
"pattern"
"pattern",

// Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
"autocomplete",
"autocorrect",
"autofocus",
"cols",
"dirname",
"disabled",
"form",
"maxlength",
"minlength",
"name",
"placeholder",
"readonly",
"required",
"rows",
"spellcheck",
"wrap"
],

/**
Expand Down Expand Up @@ -777,7 +792,8 @@ var codeInput = {
break;
default:
if (codeInput.textareaSyncAttributes.includes(name)) {
if(newValue == null) {
console.log("sync", name, oldValue, newValue);
if(newValue == null || newValue == undefined) { // TODO: Console.Log to check reaches here with disabled attribute; Fix for disabled attr removal
this.textareaElement.removeAttribute(name);
} else {
this.textareaElement.setAttribute(name, newValue);
Expand Down Expand Up @@ -939,27 +955,6 @@ var codeInput = {
return this.textareaElement.reportValidity();
}


/**
* @override
*/
setAttribute(qualifiedName, value) {
super.setAttribute(qualifiedName, value); // code-input
if(this.textareaElement != null) {
this.textareaElement.setAttribute(qualifiedName, value); // textarea
}
}

/**
* @override
*/
getAttribute(qualifiedName) {
if (this.textareaElement == null) {
return super.getAttribute(qualifiedName);
}
return this.textareaElement.getAttribute(qualifiedName); // textarea
}

/**
* Allows plugins to store data in the scope of a single element.
* Key - name of the plugin
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Fully customisable, editable syntax-highlighted textareas.",
"browser": "code-input.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"This is a front-end library, not a Node library. Please see the README for how to use.\" && exit 1"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 234d4ec

Please sign in to comment.