Issue #3457Opened May 13, 2021by RaresVlaiduc3 reactions

BUG: Custom trait input not working

Question

Hi @artf !

Version: 0.17.3

Are you able to reproduce the bug from the demo?

  • Yes
  • No

What is the expected behavior?

The input is created correctly

Describe the bug detailed

I am trying to create a custom input (checkbox) and it doesn't work.

What is the current behavior?

See attach.

Are you able to attach screenshots, screencasts or a live demo?

  • Yes (attach)
  • No

Code: image

Result: image

The area that should be some kind of "input" is not clickable.

If I am doing something wrong, let me know :)

Answers (3)

artfMay 18, 20212 reactions

@RaresVlaiduc mmm I'd expect it to work also with an HTML string... I have to check it

ahmedderkaouiMay 17, 20211 reactions

Then, in createInput() you should return an Element. So instead of returning a simple string, do this:

const el = document.createElement('div');
el.innerHTML = `<input type='checkbox'/>`
return el;
ahmedderkaouiMay 17, 20210 reactions

If you want to have a simple checkbox with label, no need to create custom trait, you can just use directly:

editor.DomComponents.addType('text', {
            model: {
              defaults: {
                traits: [
                  {type: 'checkbox', label: 'Fix position when scrolling', name: 'position-sticky'}
                ]
              }
            },
});

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.