Skip to content

Commit

Permalink
First pass at client side validation
Browse files Browse the repository at this point in the history
Added required if question is marked as mandatory
Also preliminary support for type checking (:float, :integer, :time)
Using jqueryvalidation.org for client side validation

NUBIC#34
  • Loading branch information
Paul Friedman committed Aug 1, 2013
1 parent 98225cd commit cc776ac
Show file tree
Hide file tree
Showing 10 changed files with 1,959 additions and 7 deletions.
7 changes: 5 additions & 2 deletions app/views/partials/_answer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
= ff.input :answer_id, :as => :surveyor_check_boxes, :collection => [[a.text_for(nil, @render_context, I18n.locale), a.id]], :label => false, :input_html => {:class => a.css_class, :disabled => disabled}, :response_class => a.response_class
- when "none"
- if %w(date datetime time float integer string text).include? a.response_class
= ff.input :answer_id, :as => :quiet, :input_html => {:class => a.css_class, :value => a.id}
- css_class = "#{a.css_class} surveyor_#{a.response_class}_answer"
- if q.mandatory?
- css_class << " surveyor_required"
= ff.input :answer_id, :as => :quiet, :input_html => {:class => css_class, :value => a.id}
= ff.input rc_to_attr(a.response_class),
:as => rc_to_as(a.response_class),
:label => a.text_for(:pre, @render_context, I18n.locale).blank? ? false : a.text_for(:pre, @render_context, I18n.locale),
:hint => a.text_for(:post, @render_context, I18n.locale),
:input_html => generate_pick_none_input_html(r.to_formatted_s, a.default_value_for(@render_context, I18n.locale), a.css_class, a.response_class, disabled, a.input_mask, a.input_mask_placeholder)
:input_html => generate_pick_none_input_html(r.to_formatted_s, a.default_value_for(@render_context, I18n.locale), css_class, a.response_class, disabled, a.input_mask, a.input_mask_placeholder)
- else
= a.text_for(nil, @render_context, I18n.locale)
%span.help= a.help_text_for(@render_context, I18n.locale) unless g && g.display_type == "grid"
69 changes: 69 additions & 0 deletions features/validations.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Feature: Survey with validations
As a survey participant
I want to take a survey
And be notified when I answer incorrectly

# Issue 34 - client side validation for mandatory question
@javascript
Scenario: Creating a mandatory question
Given I parse
"""
survey "Mandatory Question" do
section "Required" do
q "Type your name. This is required.", :is_mandatory => true
a "name", :string
end
end
"""
When I start the "Mandatory Question" survey
And I press "Click here to finish"
Then I should see "This field is required."

@javascript
Scenario: Creating a question with an integer answer
Given I parse
"""
survey "Integer Question" do
section "How many" do
q "How many pets do you own?"
a "Number", :integer
end
end
"""
When I start the "Integer Question" survey
And I fill in "Number" with "Eight"
And I press "Click here to finish"
Then I should see "A positive or negative non-decimal number please"

@javascript
Scenario: Creating a question with an float answer
Given I parse
"""
survey "Float Question" do
section "How many" do
q "How mmuch oil do you use?"
a "Quantity", :float
end
end
"""
When I start the "Float Question" survey
And I fill in "Quantity" with "A lot"
And I press "Click here to finish"
Then I should see "Please enter a valid number."

@javascript
Scenario: Creating a question with a time answer
Given I parse
"""
survey "Time Question" do
section "When" do
q "What time is it?"
a "Time", :time
end
end
"""
When I start the "Time Question" survey
And I press "When"
And I fill in "Time" with "0900"
When I press "Click here to finish"
Then I should see "Please enter a valid time, between 00:00 and 23:59"
Loading

0 comments on commit cc776ac

Please sign in to comment.