Issue #2952Opened August 11, 2020by krishnaeverestengineering0 reactions

Custom component is not working after saving.

Question

Hi,

I have Button-Link custom component created, and when I dragged into canvas for the first time component is detecting its attributes and styles. But after saving the component and reloads the page, custom component type is missing from that component instead its showing Link type component. How to preserve the custom components even after saving?

Answers (3)

DmitryTar1August 13, 20200 reactions
Code SnippetTEXT
You should add some type to your component and then parse it in isComponent
For example the similar button link
const components = editor.DomComponents;
  const link = components.getType('link');

components.addType('custom-link-button', {
    model: link.model.extend({
      defaults: Object.assign({}, link.model.prototype.defaults, {
        attributes: { 'link-extended': 'custom-link-button },
      }),
    }, {
      isComponent: (el) => {
        let result;

        if (el.tagName == 'A' && el.attributes['link-extended'] 
          && el.attributes['link-extended'].value === 'custom-link-button') {
          result = {
            type: 'custom-link-button',
            editable: 0
          };

          // The link is editable only if, at least, one of its
          // children is a text node (not empty one)
          const children = el.childNodes;
          const len = children.length;
          if (!len) delete result.editable;

          for (let i = 0; i < len; i++) {
            const child = children[i];

            if (child.nodeType == 3 && child.textContent.trim() != '') {
              delete result.editable;
              break;
            }
          }
        }
        
        return result;
      }
    }),
    view: link.view
  });
Ju99ernautAugust 17, 20200 reactions

@krishnaeverestengineering How are you saving and loading your work

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.