grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

How I can save dynamic text persistent on a component view?

Open jvillena opened this issue 8 years ago • 2 comments

I was trying to insert dynamic text on a component view in the HTML but when I'm saving the html hasn't got my changes. I'll try the following things:

                  var text = editorRTE.getSelected().view.$el[0].innerHTML;

                   String.prototype.splice = function(idx, rem, str) {
                       return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
                   };

                   value = text.splice(caret, 0, value);
                   editorRTE.getSelected().view.$el[0].innerHTML = value;
                   editorRTE.getSelected().view.$el[0].focus();
                   editorRTE.getSelected().set('content', value.trim());

With the code above I can inject the text in the caret position (cursor position) but the method when I save the content I'm receiving the value.trim() concat with the current text that it was in the DomDocument.

http://recordit.co/cjAUl37aGr

I tried as well to do: editorRTE.getSelected().view.render(); But it's showing me the same output: This week [email protected]@ This week Special

jvillena avatar Jul 23 '18 15:07 jvillena

To insert the text in the highlight paragraph selected I did this because I was losing the focus after opening a popup modal dialog:

              var text = editor.getSelected().view.$el[0].innerHTML;

                String.prototype.splice = function(idx, rem, str) {
                    return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
                };

                value = text.splice(caret, 0, value);
                const domComponents = editor.DomComponents;
                const component = domComponents.getWrapper().find('.gjs-comp-selected')[0];
                component.components(value.trim());
                editor.getSelected().view.$el[0].focus();
                domComponents.render();

jvillena avatar Jul 24 '18 06:07 jvillena

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.

lock[bot] avatar Sep 17 '19 09:09 lock[bot]