Issue #486Opened November 6, 2017by krunal0390 reactions

Custom Component not editable and also after traits update canvas does not update

Question

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 canvas. I have extended 'text', Also I do not get html back when I use editor.html(), Also when I click on image it does not open asset manager. I am sure I must be missing something here.

var defaultType = comps.getType('text');
var defaultModel = defaultType.model;
var defaultView = defaultType.view;
createSectionComp(comps, defaultModel, defaultView)

function createSectionComp(comps, defaultModel, defaultView) {

    comps.addType('section', {
        // Define the Model
        model: defaultModel.extend({
            // Extend default properties
            defaults: Object.assign({}, defaultModel.prototype.defaults, {

                type: 'section',
                tagName: 'section',
                title: 'Sample Title',
                attributes: {
                    'data-gjs-type': 'cust-section',
                },
                traits: [{
                    type: 'text',
                    label: 'Title',
                    name: 'title',
                    placeholder: 'eg. Leadership Development',
                    changeProp: 1,
                }],
            }),
            initialize(o, opt) {
                defaultModel.prototype.initialize.apply(this, arguments);
                this.listenTo(this, 'change:title', this.updateModelProps);
            },

            updateModelProps() {
                var md = this;
                this.set('title', md.get('title'));

            },
        }, {
            isComponent(el) {
                if ((el.getAttribute &&
                        el.getAttribute('data-gjs-type') == 'cust-section') || el.className === 'cust-section') {
                    return {
                        type: 'cust-section'
                    };
                }
            }
        }),

        // Define the View
        view: defaultView.extend({

            tagName: 'div',
            events: {},
            initialize(o) {
                defaultView.prototype.initialize.apply(this, arguments);
                this.listenTo(this.model, 'change:title', this.updateView);
            },

            updateView() {
                var rowDiv = document.createElement('section');
                rowDiv.className = "row";
                rowDiv.innerHTML = "Sample Text Please change here";
                this.custTextRightHandImage = rowDiv;

                return this.custTextRightHandImage;
            },

            render(...args) {
                defaultView.prototype.render.apply(this, args);
                this.el.appendChild(this.updateView());
                return this;
            }
        })
    });
};

Answers (2)

artfNovember 7, 20170 reactions

In your model, you don't need defining data-gjs-* it's only make sense for importing from HTML, so remove this:

attributes: {  'data-gjs-type': 'cust-section', },

and you don't need type: 'section', either. From what I see you should define addType like this

comps.addType('cust-section', {...

You can't edit this

var rowDiv = document.createElement('section');
rowDiv.className = "row";
rowDiv.innerHTML = "Sample Text Please change here";

because it's just a plain HTML, the editor works with models attached to elements, so you probably want this this.model.append('<section class="row"> Sample ...</section>') in this way you update the model tree which then reflect changes on canvas

lock[bot]September 18, 20190 reactions

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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.