wysiwyg field: Uploading images on pasting from clipboard

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • a.slyzhko
    Senior Member
    • Oct 2023
    • 109

    #1

    wysiwyg field: Uploading images on pasting from clipboard

    Hi there!

    I noticed that in EspoCRM, when you paste a file (like an image or document) into a text field, it's handled and attached properly to the related entity (e.g., added to the attachments field).

    However, this behavior doesn’t apply to the WYSIWYG field. Currently, pasting files into the WYSIWYG editor doesn't trigger the same file-handling logic, even though Summernote supports intercepting paste events.

    Would it be possible to implement similar clipboard file-paste handling for the WYSIWYG field as is already done for text fields?

    This would greatly improve user experience, especially for composing rich content with pasted screenshots or files.

    Thanks for considering this!
  • yuri
    Member
    • Mar 2014
    • 9037

    #2
    It does work for me. Been supported for many years.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • a.slyzhko
      Senior Member
      • Oct 2023
      • 109

      #3
      I mean redirect all files to attachment field. Especially images. In our case we use wysiwyg as description for tasks, and it is such a mess when users insert a lot of images to this field. We would really benefit from ability to redirect paste images to attachment field

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1301

        #4
        If this is supported for the text field i bet it would be supported via wysiwyg too. i have checked and it is supported but you have to modify the code under custom folder. in your entityDefs > your entity > your field just add this to the field
        PHP Code:
        "attachmentField""attachments" 
        then clear cache and rebuild and it should work now.
        Rabii
        Here to help :)

        Comment


        • rabii
          rabii commented
          Editing a comment
          Just tested it and it works the image was added and a new attachment is created for the image with correct (related-to) entity.

        • shalmaxb
          shalmaxb commented
          Editing a comment
          only for the record: is your image filename compatible? happened to me before, that one wrong character maybe th culprit.

        • rabii
          rabii commented
          Editing a comment
          I think i now understand what you mean. do you want to save the files saved to the multiple attachments field on your entity ? if that is the case you are right this function is not supported. But it makes sense hence the wyswig field supports inline images upload. You need to customise the field to act as you need in this case.
      • a.slyzhko
        Senior Member
        • Oct 2023
        • 109

        #5
        rabii
        Can not reproduce.
        custom/Espo/Custom/Resources/metadata/entityDefs/Task.json
        PHP Code:
        {
            
        "fields": {
                
        "cDescription": {
                    
        "type""wysiwyg",
                    
        "attachmentField""attachments",
                    
        "isCustom"true
                
        }
            }

        Attached Files

        Comment


        • rabii
          rabii commented
          Editing a comment
          as mentioned in my last comment. (I mean redirect all files to attachment field) this will not work as the field wysiwyg supports only inline image upload (although the images will be created in attachment entity). You will need to customise the field in your case to behave similar to text field. should be an easy task hence all code already exist just adopt it.
      • a.slyzhko
        Senior Member
        • Oct 2023
        • 109

        #6
        If someone will ever need this functionality, here is the simplest way I was able to find for achieving that
        PHP Code:
        define(['views/fields/wysiwyg'], function (WysiwygFieldView) {
            return class extends 
        WysiwygFieldView {
                
        enableWysiwygMode() {
                    
        super.enableWysiwygMode();

                    if (!
        this.$element || !this.$summernote || !this.params.attachmentField) {
                        return;
                    }

                    const 
        context this.$summernote.data('summernote');
                    
        context.options context.options || {};
                    
        context.options.callbacks context.options.callbacks || {};

                    
        context.options.callbacks.onImageUpload = (files) => this.recordHelper.trigger('upload-files:' this.params.attachmentFieldfiles);
                }
            }
        }) 

        Comment


        • shalmaxb
          shalmaxb commented
          Editing a comment
          Hi, thanks for the solution. Could you provide, in which folder you put this file?

        • a.slyzhko
          a.slyzhko commented
          Editing a comment
          It is individual. You can put it where ever you want in client/custom/src, but view param of your wysiwyg field should point exactly to this file.
          In my case it is client/custom/src/views/task/fields/c-description.js and view param like this

          {
          "fields": {
          "cDescription": {
          "type": "wysiwyg",
          "attachmentField": "attachments",
          "view": "custom:views/task/fields/c-description",
          "isCustom": true
          }
          }
          }
      Working...