unable to update the traits value in the HTML for custom component
Question
I have created a custom component for social icons.When selected this component i have two traits in setting facebook URL and show facebook , when i update the both it gets updated and is reflected in canvas but when i export i don't get the URL for facebook which is set via the traits. Below is the code attached.
grapesjs.plugins.add('social-icons-component', (editor, opts = {}) => {
let c = opts;
let defaults = { blocks: 'social-icons',
// Default style
defaultStyle: true,
// Default start time, eg. '2018-01-25 00:00'
startTime: '',
// Default style
defaultStyle: true,
// Default start time, eg. '2018-01-25 00:00'
startTime: '',
// Text to show when the countdown is ended
endText: 'EXPIRED',
// Date input type, eg, 'date', 'datetime-local'
dateInputType: 'date',
// Countdown class prefix
socialClssfx: 'social-icons',
// Countdown label
labelCountdown: 'Countdown',
// Countdown category label
labelCountdownCategory: 'Extra',
// Days label text used in component
labelDays: 'days',
// Hours label text used in component
labelHours: 'hours',
// Minutes label text used in component
labelMinutes: 'minutes',
// Seconds label text used in component
labelSeconds: 'seconds',
};
// Load defaults
for (let name in defaults) {
if (!(name in c))
c[name] = defaults[name];
}
// Add components
// loadComponents(editor, c);
// // Add components
// loadBlocks(editor, c);
const domc = editor.DomComponents;
const defaultType = domc.getType('default');
const textType = domc.getType('text');
const defaultModel = defaultType.model;
const defaultView = defaultType.view;
const textModel = textType.model;
const textView = textType.view;
const sfx = c.socialClssfx;
domc.addType('social-icons', {
model: defaultModel.extend({
defaults: Object.assign({}, defaultModel.prototype.defaults, {
droppable: false,
traits: [{
label: 'Facebook URL',
name: "facebook_url",
changeProp: 1,
value:"dasdsdasd",
},
{
type: "checkbox",
label: 'Facebook',
name: "facebook_show",
changeProp: 1,
value: 1,
},
],
script: function() {
}
}),
}, {
isComponent(el) {
if(el.getAttribute &&
el.getAttribute('data-gjs-type') == 'social-icons') {
return {
type: 'social-icons'
};
}
},
}),
view: defaultView.extend({
init: function() {
this.listenTo(this.model, 'change:facebook_url change:facebook_show', this.updateSrc);
const comps = this.model.get('components');
// Add a basic countdown template if it's not yet initialized
if (!comps.length) {
comps.reset();
comps.add(`
<div data-js="social-icons" >
<div data-js="social-facebook-div" class="${sfx}-block">
<a data-js="social-facebook" href="" target="_blank" style="border: none;text-decoration: none;" class="facebook">
<img src="https://www.ctltrax.com/staging/frontend/assets/files/ext-mbuilder-email-editor/assets/social/facebook.png" border="0"><!---->
</a>
</div>
<div class="${sfx}-block">
<a data-js="social-twitter" href="" target="_blank" style="border: none;text-decoration: none;" class="twitter">
<img src="https://www.ctltrax.com/staging/frontend/assets/files/ext-mbuilder-email-editor/assets/social/twitter.png" border="0"><!---->
</a>
</div>
<div class="${sfx}-block">
<a data-js="social-linkedin" href="" target="_blank" style="border: none;text-decoration: none;" class="linkedin">
<img src="https://www.ctltrax.com/staging/frontend/assets/files/ext-mbuilder-email-editor/assets/social/linkedin.png" border="0"><!---->
</a>
</div>
<div class="${sfx}-block">
<a data-js="social-youtube" href="" target="_blank" style="border: none;text-decoration: none;" class="youtube">
<img src="https://www.ctltrax.com/staging/frontend/assets/files/ext-mbuilder-email-editor/assets/social/youtube.png" border="0"><!---->
</a>
</div>
</div>
`);
}
},
updateSrc: function updateSrc() {
// var facebookUrl = this.model.querySelector('[data-js=social-facebook]');
// // var facebookDiv = this.model.querySelector('[data-js=social-facebook-div]');
var facebookUrl = this.el.querySelector('[data-js=social-facebook]');
var facebookDiv = this.el.querySelector('[data-js=social-facebook-div]');
console.log(this);
var facebook_url = this.model.get('facebook_url');
var facebook_check = this.model.get('facebook_show');
if(facebook_check){
facebookDiv.style.display = '';
facebookUrl.href = facebook_url;
}else{
facebookDiv.style.display = 'none';
facebookUrl.href = facebook_url;
}
},
}),
});
const style = c.defaultStyle ? `<style>
.${sfx} {
text-align: center;
font-family: Helvetica, serif;
}
.${sfx}-block {
display: inline-block;
margin: 0 10px;
padding: 10px;
}
.${sfx}-digit {
font-size: 5rem;
}
.${sfx}-endtext {
font-size: 5rem;
}
.${sfx}-cont,
.${sfx}-block {
display: inline-block;
}
</style>` : '';
var bm = editor.BlockManager;
bm.add('social-icons', {
label: 'Test Quote',
category: 'Extra',
content: {
content: `
${style}
`,
editable: !1,
droppable: !0,
'type':'social-icons',
style: {
"width" : "100%",
"text-align": "center",
}
},
attributes: {class:'fa fa-quote-right'}
});
});Answers (2)
Please keep track of your issues here, you're talking about the same case #1089
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1723
[QUESTION] replacing particular text in dropped component
Hi, I get the value from custom traits from what I entered but I don't know how to change the particular value in dropped component and ren...
Issue #486
Custom Component not editable and also after traits update canvas does not update
below is code i used for traits and custom section but after adding component via block, cannot edit text or trait update does not update c...
Issue #1665
Jquery selector in traits Actions
I have created a custom component and and select to its traits, this select cotains multiple URLs. in doStuff() method i've displayed the s...
Issue #1535
[Bug]: After custom component is deleted the Trait's view does not clear out
Hi, I'm using the grapesjs library version 0.14.33. I've created some custom components and I've noticed that on deleting the components th...
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.