Return span randomly in custom component
Question
I have custom component and on trait change wanted to updated html but randomly it returned span/textnode in trait change function insted of html element. Below is html generated by component and on title change want to updated h4 element.
updateTitle : function updateTitle() {
var title = this.get('title');
var linkModel = this.get("components").at(0);
if (linkModel) {
var titleContainer = linkModel.get("components").at(3);
if (titleContainer) {
var h4 = titleContainer.get("components").at(0);
if (h4) {
h4.set("content", title);
}
}
linkModel.attributes.attributes["aria-label"] = title;
linkModel.attributes.attributes["title"] = title;
}
this.set("data-title", title);
if (this.get('isCreatePage') && this.changed && this.changed.title) {
this.set('isPageCreated', false);
this.set('bespokePageUrl', '');
this.updateIsCreatePage();
}
}
- linkModel.get("components").at(0) returns "div.programme-description" correctly
- linkModel.get("components").at(1) returns "span" not sure from where it is coming
- linkModel.get("components").at(2) returns "span" not sure from where it is coming
- linkModel.get("components").at(3) returns "img.programme-content-image" correctly
- linkModel.get("components").at(4) return "div.programme-play-button-hidden" correctly
- linkModel.get("components").at(5) return "div.programme-title" correctly
here not sure from where linkModel.get("components").at(1) & linkModel.get("components").at(2) "span" are returned and they are returned randomly so not sure what is happing and due to it h4 title is not updated as index of item changes.
Answers (3)
Well from what you've posted I can't tell what is happening but definitely, there is nothing generated randomly, just go deeper with the debug.
BTW you can solve this easier by using find(query) method:
var title = this.get('title');
...
var h4 = this.find('h4')[0]; // returns an array of models
h4 && h4.set("content", title);
...
@artf I tried to debug but no luck as it is happening on some pages and not on all pages. also
this.find is undefined

Just update grapesjs
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1198
QUESTIONS : Find element in Model
I have custom component and it render below html, I want to update value of h4 tilte and other element on trait changed, but not sure how c...
Issue #513
Model and returned html issue
I have below code to create custom component and wants to retrieve updated html via editor.html() but return wrong html, I am sure I am mis...
Issue #1313
[Question] Set traits value from html on component load
I have custom component and want to set trait default values from html. below is html rendered by component. traits I am trying to set for...
Issue #1493
[QUESTION] render() works on the first time but not on subsequent calls
Hello, I've created a custom component that shows images using background-image on a <div> instead of using an <img> element. It's mostly w...
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.