Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rich_text_area input field type for ActionText shipping with Rails 6.x #1638

Closed
msdundar opened this issue Jan 30, 2019 · 18 comments
Closed

Comments

@msdundar
Copy link

msdundar commented Jan 30, 2019

Environment

  • Ruby [version]

ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux]

  • Rails [version]

6.x

  • Simple Form [version]

simple_form (4.1.0)

Current behavior

Rails 6 is close to shipping has released. ActionText is one of the most exciting features of Rails 6, and it is implemented to Rails forms as follows:

<%= form_with(model: message) do |form| %>
  <%= form.label :content %>
  <%= form.rich_text_area :content %>
<% end %>

However, simple_form doesn't seem ready to accept rich_text_area as an argument to as:.

Expected behavior

simple_form should support rich_text_area as an input type and render the ActionText form.

@msdundar msdundar changed the title Input field type for ActionText shipping with Rails 6.0.0 rich_text_area input field type for ActionText shipping with Rails 6.0.0 Jan 30, 2019
@feliperenan
Copy link
Collaborator

I'm not sure if we should include this feature at Simple Form now. @rafaelfranca any thoughts?

@alec-c4
Copy link

alec-c4 commented May 18, 2019

Hi, lads! Any news about this issue? Rails is rc1

@aruljohn
Copy link

Is simple_form going to support rich_text_area for Rails 5.2?

@bopm
Copy link

bopm commented Sep 10, 2019

So Rails 6 is out in the wild, but no news here.

@jaredmoody
Copy link

In the meantime, this is pretty trivial to implement yourself:

class RichTextAreaInput < SimpleForm::Inputs::Base
  def input(wrapper_options = nil)
    merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)

    @builder.rich_text_area(attribute_name, merged_input_options)
  end
end

@ThomasConnolly
Copy link

Trivial for you, Jared...
...but I don't know where I would put that code. In an initializer, such as simple_form.rb? I don't understand the reluctance to update the gem to be used with action_text, especially for blokes like me who only know only enough RoR to operate a single website as a volunteer.

@jaredmoody
Copy link

jaredmoody commented Sep 22, 2019

@ThomasConnolly where to put the code is more a Rails topic than SimpleForm, but I have my custom inputs in app/inputs; since app is in the Rails default autoload path, there's nothing more to do.

You could also put custom inputs under lib/inputs perhaps, in which case you would need to add a require statement to the file(s) - or add lib/inputs to config.autoload_paths in config/application.rb so that rails will autoload everything in that folder.

See the Rails Guide on autoloading for more information.

[Edit: to clarify, I'm not a contributor to this gem and can't speak to this being included - it would make sense to me to include it, I just posted my solution here in case it could help]

@ngottlieb
Copy link

@jaredmoody your input implementation loses the default trix-content class that the Rails form builder adds on the trix-editor element because you're passing in the simple_form classes instead; it messes up some of the styling of content in the editor. In my case, I just added it as a default input_html_class to the input. Of course, this doesn't allow you to remove the class, so if you need to be able to use that class in some places and not others, you'll want a different solution.

class RichTextAreaInput < SimpleForm::Inputs::Base
  def input_html_classes
    super.push('trix-content')
  end

  def input(wrapper_options = nil)
    merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)

    @builder.rich_text_area(attribute_name, merged_input_options)
  end
end

@msdundar msdundar changed the title rich_text_area input field type for ActionText shipping with Rails 6.0.0 rich_text_area input field type for ActionText shipping with Rails 6.x Jan 23, 2020
@masonhensley
Copy link

#1646 was just merged. Might consider remedied?

@evanjroberts
Copy link

I'd love to see this, now July 2020

@jaredmoody
Copy link

@evanjroberts This was merged in Feb - so it's in there!

@carlosantoniodasilva
Copy link
Member

carlosantoniodasilva commented Jul 8, 2020

@evanjroberts what @jaredmoody said :), make sure you update to 5.0.2 to get it, and let us know if you bump into issues.

@evanjroberts
Copy link

evanjroberts commented Jul 8, 2020

thanks @carlosantoniodasilva this might be the wrong place as you all seem so professional but should I run it as
<%= f.input :body, as: :rich_text_area %> OR <%= f.rich_text_area :body %>

thanks! (I'm running 5.0.2 now thanks for the info)

For simple programmers like me it may be useful to add a simple 'howto' to the Readme file on the gem page

@feliperenan
Copy link
Collaborator

Hi @evanjroberts

<%= f.input :body, as: :rich_text_area %> should work. Make sure you are using the last version released (5.0.2) and if you still cannot make it, feel free to send an example application then we can help you 🙌 .

Regarding docs, you are right. We should document this somewhere. I think it would be nice if we add a section about rich_text_area under collections. Would you willing to do that?

@carlosantoniodasilva
Copy link
Member

Maybe we can just add the mapping to the table here: https://github.com/heartcombo/simple_form#available-input-types-and-defaults-for-each-column-type, since there's plenty of examples about how to use the different mappings?

@IlianaP
Copy link

IlianaP commented Dec 3, 2020

Hello everyone! I am trying to implement the new rich_text_area, but can't seem to make it work at all. I tried both
<%= f.input :body, as: :rich_text_area %> and
<%= f.rich_text_area :body %>
But still not getting a rich text area. The field simply disappears completely.

I am running Rails 6 and have installed the simple_form gem as is in the gemfile (gem 'simple_form')

Could someone help me out?

@feliperenan
Copy link
Collaborator

Hi @IlianaP 👋

Make sure you have installed all dependencies required for rich text area: https://edgeguides.rubyonrails.org/action_text_overview.html#trix-compared-to-other-rich-text-editors

There is also this tutorial that might help you: https://gorails.com/episodes/how-to-use-action-text

@lbelenda
Copy link

lbelenda commented Jan 13, 2022

Not working for me, i am using rails 6 and simple_form 5.1.0 but i am stuck with this error
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests