Skip to content

Commit

Permalink
Merge branch '113' of https://github.com/jdzak/surveyor into jdzak-113
Browse files Browse the repository at this point in the history
* '113' of https://github.com/jdzak/surveyor:
  Adding the custom_class attribute to text answer fields. Fixes NUBIC#113.
  • Loading branch information
Mark Yoon committed Mar 18, 2011
2 parents f768773 + 0531358 commit eb09693
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/helpers/surveyor_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def rc_to_as(type_sym)
else type_sym
end
end
def generate_pick_none_input_html(response_class, default_value, css_class)
html = {}
html[:class] = css_class unless css_class.blank?
html[:value] = default_value if response_class.blank?
html
end

# Responses
def response_for(response_set, question, answer = nil, response_group = nil)
Expand Down
2 changes: 1 addition & 1 deletion app/views/partials/_answer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
- when "none"
- if %w(date datetime time float integer string text).include? a.response_class
= ff.quiet_input :answer_id, :input_html => {:class => a.css_class, :value => a.id}
= ff.input rc_to_attr(a.response_class), :as => rc_to_as(a.response_class), :label => a.split_or_hidden_text(:pre).blank? ? false : a.split_or_hidden_text(:pre), :hint => a.split_or_hidden_text(:post), :input_html => (r.as(a.response_class).blank? ? {:value => a.default_value} : {})
= ff.input rc_to_attr(a.response_class), :as => rc_to_as(a.response_class), :label => a.split_or_hidden_text(:pre).blank? ? false : a.split_or_hidden_text(:pre), :hint => a.split_or_hidden_text(:post), :input_html => generate_pick_none_input_html(r.as(a.response_class), a.default_value, a.css_class)
- else
= a.text
4 changes: 4 additions & 0 deletions features/step_definitions/surveyor_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@
q.dependency.should_not be_nil
q.dependency.rule.should == rule
end

Then /^the element "([^"]*)" should have the class "([^"]*)"$/ do |selector, css_class|
response.should have_selector(selector, :class => css_class)
end
21 changes: 20 additions & 1 deletion features/surveyor.feature
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,23 @@ Feature: Survey creation
end
end
"""
Then question "1" should have correct answer "oink"
Then question "1" should have correct answer "oink"

Scenario: Custom css class
Given the survey
"""
survey "Movies" do
section "First" do
q "What is your favorite movie?"
a :string, :custom_class => "my_custom_class"
q "What is your favorite state?"
a :string
end
end
"""
When I start the "Movies" survey
Then the element "input[type='text']:first" should have the class "my_custom_class"
# Then the element "input[type='text']:last" should not contain the class attribute



0 comments on commit eb09693

Please sign in to comment.