Not getting the Script of Block from editor.getComponents()
Question
Below is the Component that I'm adding.
> this.editor.BlockManager.add('dob-mmyy-pii', {
id: 'dob-mmyy',
label: `DOB (MM, YYYY) (PII)`,
category: 'Forms',
attributes: {class:'fa fa-birthday-cake'},
content : {
content : `<div>
<label>DOB (Month and Year)</label>
<input name='dob' class="form-control">
</div>`,
script : function(){
$( $(this).find('input[name="dob"]') ).datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function(dateText, inst) {
console.log("inst",inst)
$(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
},
beforeShow:function(){
setTimeout(()=>{$('.ui-datepicker-calendar').css("display", "none").hide();
}, 1);
},
onChangeMonthYear:function(){
setTimeout(()=>{$('.ui-datepicker-calendar').css("display", "none").hide();
}, 1);
}
})
}
}
});
and doing editor.getComponents() this is what I'm getting.
`[{"tagName":"div","type":"","name":"","removable":true,"draggable":true,"droppable":true,"badgable":true,"stylable":true,"stylable-require":"","style-signature":"","unstylable":"","highlightable":true,"copyable":true,"resizable":false,"editable":false,"layerable":true,"selectable":true,"hoverable":true,"void":false,"state":"","status":"selected","content":"<div>\n <label>DOB (Month and Year)</label>\n <input name='dob' class=\"form-control\">\n </div>","icon":"","style":"","classes":[],"attributes":{"id":"ixm7"},"traits":[{"type":"text","label":"","name":"id","min":"","max":"","unit":"","step":1,"value":"ixm7","default":"","placeholder":"eg. Text here","changeProp":0,"options":[]},{"type":"text","label":"","name":"title","min":"","max":"","unit":"","step":1,"value":"","default":"","placeholder":"eg. Text here","changeProp":0,"options":[]}],"propagate":"","components":[]}]`
I don't find the script I've defined in the block, please let me know if I'm doing something wrong.
Edit:
Found a bug similar to mine: [#1569](https://github.com/artf/grapesjs/issues/1569) but the link given there doesn't cover my issue.Answers (3)
@taufeek6 #1576
If the script is a function and you can't serialize it in a JSON. I think, in your case, you need a new custom component type (you're just adding a block) then you'll export only changed properties (the script will be part of the component definition, so you won't need it in the JSON)
Bingo! that worked perfectly fine but it's letting all of the element to be selected in the block (By directly giving the block html in 'content', content : { content : 'html' } was working fine) so how do I forbid the elements to be selected in a block?

For example, in the above image, I don't want that label, button or headings to be selected, whenever user selects, the whole block will be selected.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1034
insert element or block inside parent element
Good day, i have component, have block i have Trait on listen changes, how can I add "h1 " inside that block "'<div class="container" style...
Issue #1817
Change HTML content while block is render in editor
Hello @artf I have one block into block manager like As per above script inside the block, i want to add dynamic HTML content while this bl...
Issue #1545
[Question] How I Get ID From Block?
Hi, i have my block and I get print in Div id results from my javascript class component... How i get ID from my block ??? editor.BlockMana...
Issue #792
Script property using function don't work with blocks
In Components & JS docs there's this example: This works perfectly. But I couldn't use a function instead of a string in script, as is said...
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.