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

* Pass extra options to checkbox #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/onoff/view_helpers/action_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ module Onoff
module ViewHelpers
module ActionView
def onoff(options = {})
target = options.delete(:target)
inner = content_tag(:span, nil, { class: "onoffswitch-inner" })
switch = content_tag(:span, nil, { class: "onoffswitch-switch" })
lbl = ERB::Util.html_escape(inner)
lbl += ERB::Util.html_escape(switch)
label = content_tag(:label, lbl, {
class: "onoffswitch-label", for: options[:target] })
input = content_tag(:input, nil, {
class: "onoffswitch-label", for: target })
input = content_tag(:input, nil, options.merge({
class: "onoffswitch-checkbox",
id: options[:target], type: "checkbox" })
id: target, type: "checkbox" }))
lbl = ERB::Util.html_escape(input)
lbl += ERB::Util.html_escape(label)
content_tag(:div, lbl, { class: "onoffswitch" })
Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/views/pages/checked_switcher.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= onoff target: "myTarget", checked: true %>
1 change: 1 addition & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Dummy::Application.routes.draw do
get "/switchers", :to => "pages#switchers"
get "/checked_switcher", :to => "pages#checked_switcher"
end
7 changes: 7 additions & 0 deletions test/jquery_onoff_rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class JqueryOnoffRailsTest < ActionDispatch::IntegrationTest
assert_select "span.onoffswitch-switch"
end

test "extra options should be passed to checkbox" do
get "/checked_switcher"
assert_response :success
assert_select "input.onoffswitch-checkbox[checked]"
end


private

def clean_sprockets_cache
Expand Down