[Question] Add grapesjs color picker to a new trait type?

See original GitHub issue

I’m building a a new trait type, and would like to be able to include the grapesjs color picker inside it - any suggestions on how to do that? Right now I’m including the standard HTML color input in my “inputEl” html (along with a text field and radio button) but I would love to be able to use the one that comes with grapesJS instead, if that’s possible.

Example of where I’d like to put the grapesjs picker.

 inputEl =   `<div>SOME HTML HERE</div><div><span>Color: </span><span><input type="color" id="colorpicker" value=""></span></div><div>MORE HTML HERE</div>`

Thanks for any suggestions. Great tool, btw, thank you for creating it.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pnellesencommented, Sep 13, 2018

@nojacko I’ve modified my code a little, here’s basically what I’m doing:

 getInputEl: function() {
      if (!this.inputEl) {
        var input = document.createElement('div');
        input.innerHTML = this.inputHtml
        var inputEl = input;
        var pickerEl = inputEl.querySelector(".myolorPicker");
        pickerEl.id = "ppcp" + this.cid;
        if (!this.model.colorPickerEl) {// add the jQuery spectrum color picker to our trait editor
          this.model.colorPickerEl = editor.TraitManager.getType('color').prototype.getInputEl.apply(this, arguments);
        }
        pickerEl.appendChild(this.model.colorPickerEl)
        
        ... code to handle value changes and update other fields ...

      return this.inputEl;
}

Hope this helps. This is still a work in progress 😃

Note that the getInputEl method of the colorPicker appends a spectrum colorpicker to the body of the canvas each time it’s called, and it appears to be mapped to the element it returns, which is why I’m only calling it if I don’t already have that element as part of my model. I suspect there are probably better ways to handle this, but this is working for my app at the moment.

0reactions
lock[bot]commented, Sep 17, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Question] Add grapesjs color picker to a new trait type?
I'm building a a new trait type, and would like to be able to include the grapesjs color picker inside it - any...
Read more >
Trait Manager - GrapesJS
Add Traits to Components · Built-in trait types. Text; Number; Checkbox; Select; Color; Button · Updating traits at run-time · Define new Trait...
Read more >
rte - how can I add colorpicker on the default rich text editor of ...
I'm going to change the font color ...
Read more >
grapesjs: Versions - Openbase
Fix default color in ColorPicker https://github.com/artf/grapesjs/pull/3670 ... Added colorPicker option to color trait type, for color picker customization ...
Read more >
Third Story: Trait Setting in Grapes JS | by Code Dexterous
And also added one more tab for Trait Setting. You can simply copy below HTML there is nothing difficult here. Now it's time...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found