Skip to content

.setValue to work on [contenteditable=true] elements #2390

Closed

Description

@renatodeleao

Problem

<div contenteditable> is now widely adopted as the way to make Rich text editors on the web. I've noticed that we cannot set the value of these elementes using .setValue as it throws an error, and have to resort to manual workarounds.

Solution

when field.setValue is applied and field is <div contenteditable> element, internally VTU should override Elements textContent or innerHTML prop, depending on the value of attribute value is plaintext-only or 'true'. Since this is not widely supported, just going with innerHTML is probably easier.

} else if (tagName === 'INPUT' || tagName === 'TEXTAREA') {
element.value = value
this.trigger('input')
// trigger `change` for `v-model.lazy`
return this.trigger('change')
} else {

else if (this.attributes().contenteditable) { 
   element.innerHTML = value 
  
   this.trigger('input') 
   // trigger `change` for `v-model.lazy` 
   return this.trigger('change') 
}

Additional context

Cheers ✌️

Activity

  1. cexbrayat commented on Apr 3, 2024

    @cexbrayat
    Member

    Hi @renatodeleao

    That could be a good idea. Are you willing to open a PR that implements and documents this?

  2. added
    enhancement
    good first issue
    on Apr 3, 2024
  3. renatodeleao commented on Apr 3, 2024

    @renatodeleao
    ContributorAuthor

    @cexbrayat sure I can draft a PR. I'll let you know.

  4. Tardigrada777 commented on Jun 7, 2025

    @Tardigrada777

    @cexbrayat Hey! Please, have a look on my PR attached to this issue. Looking forward to your feedback. Thanks 🙂
    .

  5. added a commit that references this issue on Oct 4, 2026
    fc329eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions