• Resolved WanDal

    (@dawasi)


    Hello

    When I try to copy the content from an input or textarea field with the readonly attribute, the content is not copied and the clipboard remains empty. In the settings of wp-Typography I have enabled the option “Remove conditional hyphens when copying to the clipboard” (machine translation). The script clean-clipboard.min.js seems to be responsible for this. In my case sel.getRangeAt( 0 ).cloneContents() returns an empty result. If I use the function sel.toString() to read the marked content instead, it works fine. Is there a special reason why you use getRangeAt and cloneContents to get the marked content or could you use the toString function instead?

    Thanks a lot!

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author pepe

    (@pputzer)

    Hi @dawasi!

    No, there is no special reason, but that was probably the most compatible API at the time. I’ll have to dive into that and port the code to a more modern idiom.

    Thread Starter WanDal

    (@dawasi)

    Hi @pputzer

    All right, many thanks!
    In the meantime, I’ll dequeue the script on problematic pages.

    Regards
    dawasi

    Plugin Author pepe

    (@pputzer)

    I’ve been thinking about it. toString() will strip the markup, which differs from browser-native clipboard behavior.

    Plugin Author pepe

    (@pputzer)

    I’ve created a GitHub issue for this. We should discuss it further overthere, if necessary.

    Thread Starter WanDal

    (@dawasi)

    Thank you very much for your research.
    As I was able to work around the problem by dequeing the problematic scripts and as the problem cannot be solved easily, no further clarifications are necessary for me.

    Many thanks
    dawasi

    Plugin Author pepe

    (@pputzer)

    Hi @dawasi, I’ve been experimenting with this. Just to get the actual bug straight: You were having this issue when copying using from within a single form field? Not when the selection happens to include a form field?

    • This reply was modified 4 years, 10 months ago by pepe.
    Thread Starter WanDal

    (@dawasi)

    Hi @pputzer

    I would be happy to see such an effort from other plugin developers as well.

    I was having the issues when copying from within a single disabled form field.
    Users can embed certain parts of our website. To provide an easy way to copy the code, we use disabled form fields. However, the code in these fields cannot be copied if the clean-clipboard.min.js script is enabled.

    I hope this brings some clarity.

    Thanks a lot!

    Plugin Author pepe

    (@pputzer)

    Thanks. That’s an actual bug in the script. The Selection API does not really work with form fields and has no specified mechanism to reliably modify text selected in a field. (Instead, starting from release 5.7.0, when form field text is selected, the script will just do nothing.)

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Copying content in readonly form elements does not work’ is closed to new replies.