Class: CKEditor5::Rails::Hooks::SimpleForm::CKEditor5Input

Inherits:
SimpleForm::Inputs::Base
  • Object
show all
Defined in:
lib/ckeditor5/rails/hooks/simple_form.rb

Overview

Custom input type for Simple Form integration with CKEditor 5. This class enables seamless integration with Simple Form, allowing use of CKEditor 5 as a form input with all its features and configurations.

Examples:

Basic usage in a form

<%= simple_form_for @post do |f| %>
  <%= f.input :content,
    as: :ckeditor5,
    input_html: { style: 'width: 600px' },
    required: true
  %>
<% end %>

With custom preset and styling

<%= simple_form_for @post do |f| %>
  <%= f.input :content,
    as: :ckeditor5,
    preset: :custom,
    type: :inline,
    input_html: {
      style: 'width: 600px',
      class: 'custom-editor',
      initial_data: 'Hello!'
    }
  %>
<% end %>

With validation and error handling

<%= simple_form_for @post do |f| %>
  <%= f.input :content,
    as: :ckeditor5,
    required: true,
    input_html: { style: 'width: 600px' },
    error: 'Content cannot be blank'
  %>
<% end %>

Instance Method Summary collapse

Instance Method Details

#input(wrapper_options = nil) ⇒ String

Renders the CKEditor 5 input field

Parameters:

  • wrapper_options (Hash) (defaults to: nil)

    Options passed from the form wrapper

Returns:

  • (String)

    Rendered editor HTML



45
46
47
48
# File 'lib/ckeditor5/rails/hooks/simple_form.rb', line 45

def input(wrapper_options = nil)
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
  @builder.template.ckeditor5_editor(**editor_options(merged_input_options))
end