Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add configuration to wysihtml5 widget #1326

merged 3 commits into from

3 participants



I'd love to write a patch to allow configuration of the wysihtml5 widget from the rails_admin config DSL. I'd like to be able to set the first set of options here:

Would such a patch be accepted? If so, I'll give it a shot!


I began work on a patch, but the spec fails. Following the example of the other wysihtml5 spec, I'm checking for existence (and absence) of the button elements I'm enabling/disabling with the config options. But because they are created with javascript, capybara won't ever see them.

I'd be happy to rework the spec if you can give me an idea about how to test this feature! This is working with manual tests.

Additionally, I'm not totally thrilled with the use .to_json and $.parseJSON and am open to alternative means of data sharing.



Hello @ahhrrr

We don't have any way to test JS at the moment. Just test the JSON presence, it'll be fine.

Is it ready to be merged or do you still need some time ?


Hi @bbenezech, I've updated the spec as you requested. It failed one of the CI jobs, but it appears to be because of a bundler issue. So, I think it should be ready to merge. Let me know if there's anything else you need.


Perfect! Thank you very much.

I'll rebase it to merge. Thanks.

@bbenezech bbenezech merged commit d883601 into sferik:master

1 check failed

Details default The Travis build failed

Awesome! Thank you @ahhrrr. But i'm having a problem.

When access directly a path (Ex. '/admin/posts/new'), it works great, like you did at the spec tests. But when access navigating (Ex. Click link 'Add post'), it doesn't load setted configurations.

Are you having the same problem?
Is it a problem with pjax?

Thank you for help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
9 app/assets/javascripts/rails_admin/
@@ -191,19 +191,20 @@ $(document).live 'rails_admin.dom_ready', ->
# bootstrap_wysihtml5
- goBootstrapWysihtml5s = (array) =>
+ goBootstrapWysihtml5s = (array, config_options) =>
array.each ->
- $(@).wysihtml5()
+ $(@).wysihtml5(config_options)
array = $('form [data-richtext=bootstrap-wysihtml5]').not('.bootstrap-wysihtml5ed')
if array.length
@array = array
if not window.wysihtml5
options = $(array[0]).data('options')
+ config_options = $.parseJSON(options['config_options'])
$('head').append('<link href="' + options['csspath'] + '" rel="stylesheet" media="all" type="text\/css">')
$.getScript options['jspath'], (script, textStatus, jqXHR) =>
- goBootstrapWysihtml5s(@array)
+ goBootstrapWysihtml5s(@array, config_options)
- goBootstrapWysihtml5s(@array)
+ goBootstrapWysihtml5s(@array, config_options)
3  app/views/rails_admin/main/_form_text.html.haml
@@ -20,7 +20,8 @@
richtext = 'bootstrap-wysihtml5'
js_data = {
:csspath => field.bootstrap_wysihtml5_css_location,
- :jspath => field.bootstrap_wysihtml5_js_location
+ :jspath => field.bootstrap_wysihtml5_js_location,
+ :config_options => field.bootstrap_wysihtml5_config_options.to_json
richtext = false
7 lib/rails_admin/config/fields/types/text.rb
@@ -65,6 +65,13 @@ class Text < RailsAdmin::Config::Fields::Base
+ # If you want to have a different toolbar configuration for wysihtml5
+ # you can use a Ruby hash to configure these options:
+ #
+ register_instance_option(:bootstrap_wysihtml5_config_options) do
+ nil
+ end
register_instance_option(:bootstrap_wysihtml5_css_location) do
16 spec/integration/config/edit/rails_admin_config_edit_spec.rb
@@ -793,6 +793,22 @@ class HelpTest < Tableless
visit new_path(:model_name => "draft")
should have_selector('textarea#draft_notes[data-richtext="bootstrap-wysihtml5"]')
+ it "should include custom wysihtml5 configuration" do
+ RailsAdmin.config Draft do
+ edit do
+ field :notes do
+ bootstrap_wysihtml5 true
+ bootstrap_wysihtml5_config_options :image => false
+ bootstrap_wysihtml5_css_location 'stub_css.css'
+ bootstrap_wysihtml5_js_location 'stub_js.js'
+ end
+ end
+ end
+ visit new_path(:model_name => "draft")
+ should have_selector("textarea#draft_notes[data-richtext=\"bootstrap-wysihtml5\"][data-options]")
+ end
describe "Paperclip Support" do
Something went wrong with that request. Please try again.