Issue #2515Opened January 19, 2020by ikenderham9 reactions

Allow only one h1 tag on every page

Question

Hello

Is it possible to only allowing one h1 tag on the every page?

I need to make sure that we only can drag one h1 tag into the canvas. What to do? :-)

Answers (3)

artfJanuary 21, 20204 reactions

@pouyamiralayi thanks as always for the huge support ❤️

BTW @ikenderham keep in mind that

editor.getComponents().filter(comp => comp.get('tagName') == tag).length > 1

is correct but only if need to check components as first children of editor.getComponents() (which returns children of the main wrapper)

If you need to check ALL components (including also nested children) you can use this

editor.getWrapper().find('h1').length > 1
pouyamiralayiJanuary 20, 20203 reactions

@ikenderham

editor.on('component:add', component => {
            const tag = component.get('tagName')
            if (tag == 'h1') {
                if (editor.getComponents().filter(comp => comp.get('tagName') == tag).length > 1) {
                    component.remove()
                }
            }
        })

cheers!

ikenderhamJanuary 20, 20202 reactions

You are so nice! How can I thank you?? Thanks alot! Khdafesممنون I will try this example tomorrow on work. I just follwed you on github !

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.