polymer-quill icon indicating copy to clipboard operation
polymer-quill copied to clipboard

Two way data binding is not working

Open hariprasadiit opened this issue 8 years ago • 12 comments

I think two way data binding for the content is not working.

steps to reproduce.

  1. set the initial content.
  2. if we edit content in the editor, the changes will update the property from the host.
  3. try to change the property by some other means. it will not update the editor content.

probable cause :

polymer-quill respects the data binding system. but after setting the initial content to the quill, data flow is only one way, i.e from quill to content property.

probably it can be solved by using an observer to observe the content property, then change the quill content whenever it changes.

I'll try to use observer to see if this solves the problem.

hariprasadiit avatar Sep 20 '16 15:09 hariprasadiit

using observer doesn't solve the problem. It creates new problem of duplicate content being set to the quill editor and also resets the cursor position.

probably providing method to change entire content of the quill might work?

hariprasadiit avatar Sep 20 '16 15:09 hariprasadiit

I still trying to figure this one out. Once I do I will update.

chuckh avatar Sep 27 '16 17:09 chuckh

Just release a new version of polymer-quill 0.6.0. I added a change event which I got working with saving and loading using iron-localstorage. See the 4th demo (last) at https://chuckh.github.io/polymer-quill/components/polymer-quill/demo/.

I also was able to use the change event to get real time editing working with Firebase.

chuckh avatar Sep 29 '16 23:09 chuckh

Hi Chuck,

Thanks for the update.

two way data binding is still not working. from polymer-quill to host, data binding is working but not the other way. so i don't see any use for change event.

it seems you've set an observer for the content but it's not implemented. I've tried observer approach, but it creates additional problems. so if we want to reset the quill editor content,i think it's better to expose a function to do that.

like

in polymer-quill

resetContent : function(content){
          this.quill.root.innerHTML = content  // for save as HTML
     }

usage in host

this.$.quillEditor.resetContent(content);

hariprasadiit avatar Oct 01 '16 06:10 hariprasadiit

unfortunately the problem didn't solved. I think @hariprasadiit suggested good solution of this problem. I used invokation on this function in _contentChanged handler in async mode and this worked for me. Can you update this in new version? thank you

misterzorgy avatar Dec 14 '16 13:12 misterzorgy

@hariprasadiit @misterzorgy I made the suggested change on this commit https://github.com/chuckh/polymer-quill/commit/c8067abf5658e1eb1938415d709d8f926de32be5 with some additional logic. Let me know if this fixes this issue.

chuckh avatar Dec 21 '16 01:12 chuckh

I just released polymer-quill version 0.8.0 https://github.com/chuckh/polymer-quill/releases/tag/v0.8.0. This includes the following:

  • Updated to Quill 1.1.8
  • useContentReset flag, set true to use @hariprasadiit above fix use-content-reset="true"
  • Added more demos
  • polymer-html-render renders Quill HTML. More info at: https://chuckh.github.io/polymer-quill/components/polymer-quill/#polymer-quill-html-render
  • and more

chuckh avatar Dec 23 '16 16:12 chuckh

In my situation, when useContentReset is true then my editor goes haywire and resets focus to the beginning of document as I am typing. But I still need this to bring in external docs from db.

So what I do is useContentReset to true, set content, then useContentReset to false. Decent workaround.

petecarapetyan avatar Jan 31 '17 15:01 petecarapetyan

@petecarapetyan yes, I have same issue. your solution works to me. thank you. code here.

<polymer-quill
                    id="quillEditor"
                    store-as="html"
                    save-interval="500"
                    content="{{commentContent}}"></polymer-quill>
this.$.quillEditor.useContentReset = true;
this.commentContent = "";
this.$.quillEditor.setContent();
this.$.quillEditor.useContentReset = false;

AutumnSky avatar Feb 27 '17 15:02 AutumnSky

@AutumnSky I'm new to Polymer. Can you please tell me where have you placed the following code :

this.$.quillEditor.useContentReset = true;
this.commentContent = "";
this.$.quillEditor.setContent();
this.$.quillEditor.useContentReset = false;

atifwaqar avatar Apr 20 '17 11:04 atifwaqar

@atifwaqar apply that logic to where you want to reset quillEditor's content. In my case, set the content to null when user complete sending text. or, set the default string when user first see the polymer editor.

another code here.

var quillEditor = this.$$('#quillEditor'); quillEditor.useContentReset = true; this.formData = { "title": this.document.title, "content": this.document.content }; quillEditor.setContent(); quillEditor.useContentReset = false;

ps. Sorry for poor English...

AutumnSky avatar Apr 21 '17 09:04 AutumnSky

I see the same issue as @petecarapetyan, wherein use-content-reset constantly moves the caret to the start of the editing area. The data itself has updated properly from the JS code, at least. Any chance the attribute could work without this bug?

ghost avatar Oct 02 '17 19:10 ghost