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,...
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 wan...
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...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.