ppetrov

ppetrov

Hello,

This is my actual first attempt to write a form with external html editor in textarea field.

That i have done:

  1. I generated the form using:
    mix phx.gen.html Content Article articles heading:string tag:string slug:string article:text

  2. Updated ecto

  3. Added the CKeditor in in root.html.heex using:

  4. I have added the additional script from here within the article_form.html.heex and i can see the field updated and i can use the editor.

The problem:
When i press submit it gives me error that the field is empty.

What i tried:
I am very bad in JS so please be understanding. I got the idea that i have to collect the data from the editor and ‘send/push’ it to the form somehow (my guess is to the id of the original field) but i can’t get it to work. I have read few other topics from here but i don’t really get how to make it work.

I will appreciate if someone can guide me to the solution.

Regards,
Peter

Showing Posts 1 to 9

TwistingTwists

TwistingTwists

Can you show some code?
Have you done phx-update=ignore ?

ppetrov

ppetrov OP

Hey TwistingTwists,

I have not done any phx-update changes. That is all my code in the form. I am not sure even where to put that.

<.simple_form :let={f} for={@changeset} action={@action}>
  <.error :if={@changeset.action}>
    Oops, something went wrong! Please check the errors below.
  </.error>
  <.input field={f[:heading]} type="text" label="Heading" />
  <.input field={f[:tag]} type="text" label="Tag" />
  <.input field={f[:slug]} type="text" label="Slug" />
  <.input field={f[:article]} type="text" label="Article" />
  <:actions>
    <.button id="submit">Save Article</.button>
  </:actions>
</.simple_form>

<script>
let editor;

ClassicEditor
    .create( document.querySelector( '#article_article' ) )
    .then( newEditor => {
        editor = newEditor;
    } )
    .catch( error => {
        console.error( error );
    } );

// Assuming there is a <button id="submit">Submit</button> in your application.
editor.model.document.on( 'change:data', () => {
    console.log( editor.getData() );
} );

</script>
ppetrov

ppetrov OP

Sorry, the console.log was me trying to see if something comes out. The actual line is:

    const editorData = editor.getData();
ppetrov

ppetrov OP

The problem with that is i am not sure how they are suppose to work exactly. I guess i have to dig into it and see what i can do.

ppetrov

ppetrov OP

OK, so i figured it out. The editor is expecting to have the textarea instead of text field type. If i change it in the form then all works just fine.

Wigny

Wigny

This blog post may be useful to guide you how to setup the editor.

ppetrov

ppetrov OP

Thanks. That will be an upgrade that i might want to do. Funny enough that is a paid feature on the ck editor and with some additional coding it could make it even better than the paid service.

Mati365

Mati365

I recently made integration to simplify usage of the editor. It should be much more intuitive.

https://github.com/Mati365/ckeditor5-phoenix

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews