Get 2025 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $99
Get for 99$

CKEditor - how to save text to hex color not hsl


I want to save text to hex format. But metronic using default hsl. How to change colorPicker format?
It saved like this:
"<p><span >TEST</span></p>"


I tried as below but it didn't work

DecoupledEditor
.create(document.querySelector("#kt_docs_ckeditor_document"))
.then(editor => {
const toolbarContainer = document.querySelector( "#kt_docs_ckeditor_document_toolbar" );

toolbarContainer.appendChild( editor.ui.view.toolbar.element );

toolbarContainer.defaultConfig = {
fontColor: {
colorPicker: {
// Use "hex" format for output instead of "hsl".
format: "hex"
}
},
fontBackgroundColor: {
colorPicker: {
// Use "hex" format for output instead of "hsl".
format: "hex"
}
},
};
})
.catch(error => {
console.error(error);
});


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Great to hear that it worked! If you need further assistance, feel free to ask.



Hi Merve Erbilici Tan

you need to correctly set the color picker options in the editor's configuration. Here is how you can adjust your code:

Set the Color Picker Format: You need to configure the fontColor and fontBackgroundColor options correctly in the editor configuration. This should be done in the DecoupledEditor.create method.

Properly Configure the Editor: Ensure that the configuration is applied correctly by including it in the create method.

Here's how you can modify your code to ensure the color picker uses hex format:

DecoupledEditor
.create(document.querySelector("#kt_docs_ckeditor_document"), {
toolbar: {
items: [
"heading", "|",
"bold", "italic", "link", "bulletedList", "numberedList", "blockQuote", "|",
"fontColor", "fontBackgroundColor", "|",
"insertTable", "mediaEmbed", "undo", "redo"
]
},
fontColor: {
colors: [
{
color: "hsl(0, 0%, 0%)",
label: "Black"
},
{
color: "hsl(0, 0%, 30%)",
label: "Dim grey"
},
{
color: "hsl(0, 0%, 60%)",
label: "Grey"
},
{
color: "hsl(0, 0%, 90%)",
label: "Light grey"
},
{
color: "hsl(0, 0%, 100%)",
label: "White",
hasBorder: true
},
{
color: "hsl(0, 75%, 60%)",
label: "Red"
},
{
color: "hsl(30, 75%, 60%)",
label: "Orange"
},
{
color: "hsl(60, 75%, 60%)",
label: "Yellow"
},
{
color: "hsl(90, 75%, 60%)",
label: "Light green"
},
{
color: "hsl(120, 75%, 60%)",
label: "Green"
},
{
color: "hsl(150, 75%, 60%)",
label: "Aquamarine"
},
{
color: "hsl(180, 75%, 60%)",
label: "Turquoise"
},
{
color: "hsl(210, 75%, 60%)",
label: "Light blue"
},
{
color: "hsl(240, 75%, 60%)",
label: "Blue"
},
{
color: "hsl(270, 75%, 60%)",
label: "Purple"
}
],
columns: 5,
colorPicker: {
format: "hex"
}
},
fontBackgroundColor: {
colors: [
{
color: "hsl(0, 0%, 0%)",
label: "Black"
},
{
color: "hsl(0, 0%, 30%)",
label: "Dim grey"
},
{
color: "hsl(0, 0%, 60%)",
label: "Grey"
},
{
color: "hsl(0, 0%, 90%)",
label: "Light grey"
},
{
color: "hsl(0, 0%, 100%)",
label: "White",
hasBorder: true
},
{
color: "hsl(0, 75%, 60%)",
label: "Red"
},
{
color: "hsl(30, 75%, 60%)",
label: "Orange"
},
{
color: "hsl(60, 75%, 60%)",
label: "Yellow"
},
{
color: "hsl(90, 75%, 60%)",
label: "Light green"
},
{
color: "hsl(120, 75%, 60%)",
label: "Green"
},
{
color: "hsl(150, 75%, 60%)",
label: "Aquamarine"
},
{
color: "hsl(180, 75%, 60%)",
label: "Turquoise"
},
{
color: "hsl(210, 75%, 60%)",
label: "Light blue"
},
{
color: "hsl(240, 75%, 60%)",
label: "Blue"
},
{
color: "hsl(270, 75%, 60%)",
label: "Purple"
}
],
columns: 5,
colorPicker: {
format: "hex"
}
}
})
.then(editor => {
const toolbarContainer = document.querySelector("#kt_docs_ckeditor_document_toolbar");
toolbarContainer.appendChild(editor.ui.view.toolbar.element);
})
.catch(error => {
console.error(error);
});


This configuration ensures that the color picker for fontColor and fontBackgroundColor uses the hex format. Make sure that the toolbar items include fontColor and fontBackgroundColor to enable the color picker.

Let me know if you need further assistance!



Hi Faizal, thank you soo much. I only changed color hsl to hex. Its worked


DecoupledEditor.create(document.querySelector("#kt_docs_ckeditor_document"), {
toolbar: {
items: [ "heading", "|", "bold", "italic", "link", "bulletedList", "numberedList", "blockQuote", "|", "fontColor", "fontBackgroundColor", "|", "insertTable", "mediaEmbed", "undo", "redo" ]
},
fontColor: {
colors: [
{
color: "#000000",
label: "Black"
},
{
color: "#4D4D4D",
label: "Dim grey"
},
{
color: "#999999",
label: "Grey"
},
{
color: "#E6E6E6",
label: "Light grey"
},
{
color: "#FFFFFF",
label: "White",
hasBorder: true
},
{
color: "#E64D4D",
label: "Red"
},
{
color: "#E6994D",
label: "Orange"
},
{
color: "#E6E64D",
label: "Yellow"
},
{
color: "#99E64D",
label: "Light green"
},
{
color: "#4DE64D",
label: "Green"
},
{
color: "#4DE699",
label: "Aquamarine"
},
{
color: "#4DE6E6",
label: "Turquoise"
},
{
color: "#4D99E6",
label: "Light blue"
},
{
color: "#4D4DE6",
label: "Blue"
},
{
color: "#994DE6",
label: "Purple"
}
],
columns: 5,
colorPicker: {
format: "hex"
}
},
fontBackgroundColor: {
colors: [
{
color: "#000000",
label: "Black"
},
{
color: "#4D4D4D",
label: "Dim grey"
},
{
color: "#999999",
label: "Grey"
},
{
color: "#E6E6E6",
label: "Light grey"
},
{
color: "#FFFFFF",
label: "White",
hasBorder: true
},
{
color: "#E64D4D",
label: "Red"
},
{
color: "#E6994D",
label: "Orange"
},
{
color: "#E6E64D",
label: "Yellow"
},
{
color: "#99E64D",
label: "Light green"
},
{
color: "#4DE64D",
label: "Green"
},
{
color: "#4DE699",
label: "Aquamarine"
},
{
color: "#4DE6E6",
label: "Turquoise"
},
{
color: "#4D99E6",
label: "Light blue"
},
{
color: "#4D4DE6",
label: "Blue"
},
{
color: "#994DE6",
label: "Purple"
}
],
columns: 5,
colorPicker: {
format: "hex"
}
},
colorButton_enableMore: true
}).then(editor => {
const toolbarContainer = document.querySelector("#kt_docs_ckeditor_document_toolbar");
toolbarContainer.appendChild(editor.ui.view.toolbar.element);
}).catch(error => {
console.error(error);
});


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(