PricingBlog

Set input on child text node for contenteditable element

  • tomthebigtree-1283558728095895616

    Tom Ireland

    1 year ago

    I'm back to working on my RTE again (pure toddle) for my Shipped app project and I'm doing v2. I have created components for each element e.g. h1, p, etc., and the elements have contenteditable set to true.

    On input, I'm getting event > target > textContent to get the content as I type and setting this in a variable in the component. I have the text node set to the variable content.

    On input, this adds content to the text node (in reverse 🙄 ) but it's also adding content in the element as well e.g. <p>Some content<span>Some content</span></p>

    I'd like to just populate the <span> (text node) with content that is input.

    I did figure out a way to do this last year I'm sure but I just cannot figure it out.

    Any pointers?
  • tomthebigtree-1283559886768312426

    Tom Ireland

    1 year ago

    If I remove the <span> (text node), this works without any issue and I can capture data in whatever format I like for saving in the database but then I'd have a problem rendering it in toddle in those elements without the <span>.