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

Redundant initial formControl valueChanges emit from quill-editor

Open yuwu9145 opened this issue 3 years ago • 8 comments

When using [formControl] to <quill-editor>, it emit the default value through valueChanges observable.

This behaviour is inconsistent with the default Angular reactive form (no initial value emit but only emits when there are user changes)

Steps to reproduce

  1. Open demo link
  2. Open developer tool
  3. The default value can been found in console log
  4. By comparing the default Angular reactive form behaviour (found from this link). There is no initial value in console log

yuwu9145 avatar Jun 02 '22 02:06 yuwu9145

feel free to contribute and send me a pr :)

KillerCodeMonkey avatar Jun 02 '22 08:06 KillerCodeMonkey

sadly i have no solution for that. This change is triggered, because i try to keep validators in sync after the quill editor is initialized. So the control/model does have the correct valid state and classes.

Seems like this triggers a change

KillerCodeMonkey avatar Jun 02 '22 10:06 KillerCodeMonkey

Maybe skip(1) to mimic angular valueChanges

this.profileForm.valueChanges
    .pipe(skip(1))
    .subscribe((value) => console.log(value));

IsaacSomething avatar Dec 27 '22 18:12 IsaacSomething

@IsaacSomething and maybe check if the model/control is marked as touched and reset it, if needed

KillerCodeMonkey avatar Oct 13 '23 09:10 KillerCodeMonkey

I have the same problem, is there any update on this? I mean why would you emit valuechanges when nothing has changed? I have a formControl that has the default value and when I pass it to the quill editor it emits the same value...

imaliouris avatar Oct 19 '23 07:10 imaliouris

like described by IsaacSomething use the rxjs operator "skip" to ignore the first trigger.

KillerCodeMonkey avatar Oct 19 '23 07:10 KillerCodeMonkey

Thats not the proper way.. I have a formGroup that I track its changes and I dont always have a quill editor, or I may have more than one, so I can't just skip the first value.. Furthermore its not good for developer experience as it's not clear why this skip happens..

imaliouris avatar Oct 19 '23 07:10 imaliouris

you can try to solve the issue and send a pr. but as i described above i have not idea how to solve it without breaking other functionality

KillerCodeMonkey avatar Oct 19 '23 07:10 KillerCodeMonkey

I added a hint to the readme about that issue: https://github.com/KillerCodeMonkey/ngx-quill?tab=readme-ov-file#known-issues

KillerCodeMonkey avatar Mar 26 '24 14:03 KillerCodeMonkey