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

Is it possible to set the code-input element to read-only? #59

Closed
vcdomith opened this issue Oct 5, 2023 · 6 comments · Fixed by #60
Closed

Is it possible to set the code-input element to read-only? #59

vcdomith opened this issue Oct 5, 2023 · 6 comments · Fixed by #60
Assignees

Comments

@vcdomith
Copy link

vcdomith commented Oct 5, 2023

I was wondering if it is possible to set this element to a read-only state, so that in one page you write the code then it is shown in another page without the user being able to edit it.

@WebCoder49
Copy link
Owner

The disabled attribute currently can set this into a read-only state but there is a bug which means it cannot be reversed (as it reads the new value as undefined and sets the textarea's disabled attribute to "undefined" rather than removing it)!

I will try to fix the bug this weekend, or if you understand the codebase and want to do it via a pull request, please let me know.

@WebCoder49 WebCoder49 self-assigned this Oct 5, 2023
@WebCoder49
Copy link
Owner

WebCoder49 commented Oct 5, 2023

Here's the JavaScript code:

let codeInput = document.querySelector("code-input"); // Or get your element in another way
codeInput.setAttribute("disabled", true); // Make read-only
codeInput.removeAttribute("disabled"); // Make editable again

@vcdomith
Copy link
Author

vcdomith commented Oct 5, 2023

That's perfect, it'll work wonders, as the code-input editor is another template I don't think it'll interfere. Thank you very much! This element is a life-saver!

@WebCoder49
Copy link
Owner

I will try to implement the bug fix this weekend - please could I check that you are using the latest version 2.0?

@WebCoder49 WebCoder49 linked a pull request Oct 7, 2023 that will close this issue
@WebCoder49
Copy link
Owner

I have released this functionality in v2.0.3. Please let me know if it doesn't work.

@WebCoder49
Copy link
Owner

For your information, please see the updated code snippets above (it turns out I was slightly wrong at first). If you want, you could use the readonly attribute as mentioned here instead of disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants