stu
February 10, 2020, 10:28pm
1
Hi,
I need my users to be able to format text they enter into a TextArea (or similar).
Such as:
Bold
Italic
Underline
Ordered List
Unordered List
Link (URL)
Having searched the forum and Google, I’ve not managed to find anything so I’m not sure if this has been done before within Anvil?
Any help would be much appreciated.
A mock up below for clarity:
I use Quill and it is awesome.
Here are some links to posts from prior discussion to help you get started.
Objective: Display of moderately-formatted help text, or other instructional text. You’re reading a positive example right now.
Should handle
relative font sizing (for titles and headings)
bold, italic, underline
proportional and monospaced fonts
superscript and subscript (e.g., for minor math effects)
numbered and unnumbered lists
word wrap
Raw format may be a subset of XHTML, XML, Markdown, ReStructuredText (such as used to build Python’s documentation), etc… Strictly limited, for good s…
If you have any questions just reply here and I can help you. We heavily use the rich text editor in our application so i’ve tackled alot of the issues that you might run into.
5 Likes
stu
February 11, 2020, 8:04am
3
That is fantastic. Exactly what I need.
Thank you.
1 Like
here are some samples of how I use the styling, how i collect the html, and how I put text in the editor.
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote' , 'link'],
// custom button values
//[{ 'list': 'ordered'}, { 'list': 'bullet' }], // superscript/subscript
//[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
//[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
// [{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
// [{ 'font': [] }],
[{ 'align': [] }],
['clean'] // remove formatting button
];
//var container = $(this).find(".editor-container").get(0);
var quill = new Quill("#editor-container", {
modules: {
toolbar: toolbarOptions
},
theme: 'snow'
});
function getContents() {
var delta = quill.getContents();
return quillGetHTML(delta);
}
function quillGetHTML(inputDelta) {
var tempCont = document.createElement("div");
(new Quill(tempCont)).setContents(inputDelta);
return tempCont.getElementsByClassName("ql-editor")[0].innerHTML;
}
function insertCanned(canned_html) {
quill.clipboard.dangerouslyPasteHTML(canned_html);
}
2 Likes