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)
@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
@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!
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.
Issue #1804
Applying two different traits on same html tag but applies only one
Hello @artf , If we need to initialize two traits on same HTML tag then it's possible or not? Actually i define two different traits on sam...
Issue #2744
[QUESTION] Disable a block drag&drop
Hello everyone, I would like to make forbidden the drop of one block before another specific one. Context : i've create a new trait for som...
Issue #1184
Is it possible to have only one button in the canvas
hi,bro。I want to implement that there is only one button in the canvas.when i drag the second,it will not be placed correctly or the button...
Issue #1401
help for create component
Hello, I need to do two things:I need a component to create a button with specifically id and disabled edit the id.Define one tag HTML impo...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.