Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easyimage don't trigger change after upload success when using angular reactive forms #237

Open
thalisvilela opened this issue Dec 21, 2022 · 3 comments
Labels
status:confirmed An issue confirmed by the development team. type:bug A bug.

Comments

@thalisvilela
Copy link

thalisvilela commented Dec 21, 2022

When using easyimage with Reactive forms, it does not trigger the change on the form control, passing invalid data to the backend.
Only the placeholder image element tiggers the change, the one having the placeholder blob address:

<figure class="easyimage easyimage-full"><img alt="" src="blob:http://localhost:4200/ca2c741f-ea9d-4d67-8cbb-379d050f6ddd" width="3840" />
<figcaption></figcaption>

When the image upload response arrive, the change to the src parameter to the final image url dont't trigger change, so, if you hit save in your app, the blob value gets sent to whatever backend functionality.

If after the image upload we make any change, then the correct src value with the correct image url gets passed.

@jacekbogdanski
Copy link
Member

From what I see, the easyimage (or rather upload loader) is not firing the change event upon finishing the upload process:
https://github.com/ckeditor/ckeditor4/blob/a41004afe2479972c7775d42d5d359a2d085dbf1/plugins/easyimage/plugin.js#L341-L352
My assumption is that Reactive Forms are integrated with the ControlValueAccessor interface that is implemented by CKEditor 4 React component and is based on onChange event:
https://github.com/ckeditor/ckeditor4-angular/blob/master/src/ckeditor/ckeditor.component.ts#L290

That's the reason why you see the properly updated src value of the image when you make some editor changes - the change event is fired and forms are notified about new editor content.

Therefore, the proper fix for this issue should be made in the editor itself, but I'm leaving that issue open here since we will need to write some test coverage for that anyway.

@jacekbogdanski jacekbogdanski added status:confirmed An issue confirmed by the development team. type:bug A bug. labels Dec 28, 2022
@jacekbogdanski
Copy link
Member

Related issue in CKEditor 4 repo: ckeditor/ckeditor4#4856

@thalisvilela
Copy link
Author

For anyone having this issue, i got around it by firing a 'change' event from the editor instance, inside a setTimeout. The delay amount appears to be irrelevant, but i set it to 100ms just in case.

ckEditorConfig: any = { 
      // ... other configurations are here, including the easyimage configurations
       on:{
            fileUploadResponse:($event)=>{
                setTimeout(()=>{
                    $event.editor.fire('change')
                },100)
            }
        }
    }

And in the html:
<ckeditor [config]="ckEditorConfig"></ckeditor>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:confirmed An issue confirmed by the development team. type:bug A bug.
Projects
None yet
Development

No branches or pull requests

2 participants