Search code examples
javascriptasp.net-coreckeditorckeditor5

How do I pass the <div> element (to get its id) from CKEditor-->uploads()-->_initRequest()?


I have 2 CKEditor fields () in the View.

<div id="editor_1">
     @Html.Raw(@Model.Description_1)
</div>

<div id="editor_2">
     @Html.Raw(@Model.Description_2)
</div>

There is a code that transmits the uploaded image to the controller:

<script>

class MyUploadAdapter {
    
    upload() {
        return this.loader.file
            .then( file => new Promise( ( resolve, reject ) => {
                this._initRequest();
                this._initListeners( resolve, reject, file );
                this._sendRequest( file );
            } ) );
    }

    _initRequest() {
        const xhr = this.xhr = new XMLHttpRequest();
    }
}

</script>

How do I pass in _initRequest() a link to the elements and to understand which field the user is uploading the image to (I need to get the field id)? I tried to figure it out in the controller (in Request class) where I receive the uploaded image, but I couldn't.

foreach (IFormFile photo in Request.Form.Files)

Thanks!


Solution

  • I solved the problem by myself by getting the focus - in which field the image is uploaded. The issue is closed. https://ckeditor.com/docs/ckeditor5/latest/framework/deep-dive/ui/focus-tracking.html