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

Fix hide/show group based on dependency #504

Open
wants to merge 5 commits into
base: simple_form
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
41 changes: 25 additions & 16 deletions lib/assets/javascripts/surveyor/jquery.surveyor.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,29 @@ jQuery(document).ready(function(){
});

jQuery("form#survey_form input, form#survey_form select, form#survey_form textarea").change(function(){
var elements = [$('[type="submit"]').parent(), $('[name="' + this.name +'"]').closest('li')];

question_data = $(this).parents('div[id^="q_"],tr[id^="q_"]').
find("input, select, textarea").
add($("form#survey_form input[name='authenticity_token']")).
serialize();
$.ajax({
type: "PUT",
url: $(this).parents('form#survey_form').attr("action"),
data: question_data, dataType: 'json',
success: function(response) {
successfulSave(response);
}
});
var that = this,
update = function(){
var elements = [$('[type="submit"]').parent(), $('[name="' + that.name +'"]').closest('li')];

question_data = $(that).parents('div[id^="q_"],tr[id^="q_"]').
find("input, select, textarea").
add($("form#survey_form input[name='authenticity_token']")).
serialize();
$.ajax({
type: "PUT",
url: $(that).parents('form#survey_form').attr("action"),
data: question_data, dataType: 'json',
success: function(response) {
successfulSave(response);
}
});
};
if ($(that).is('input[data-input-mask]')) {
clearTimeout($(that).data('surveyor-change-timer'));
$(that).data('surveyor-change-timer', setTimeout(update, 1));
} else {
update();
}
});

// http://www.filamentgroup.com/lab/update_jquery_ui_slider_from_a_select_element_now_with_aria_support/
Expand All @@ -106,7 +115,7 @@ jQuery(document).ready(function(){
}

function showElement(id){
group = id.match('^question_group_') ? true : false;
group = id.match('^g_') ? true : false;
if (group) {
jQuery('#' + id).removeClass("g_hidden");
} else {
Expand All @@ -115,7 +124,7 @@ jQuery(document).ready(function(){
}

function hideElement(id){
group = id.match('^question_group_') ? true : false;
group = id.match('^g_') ? true : false;
if (group) {
jQuery('#' + id).addClass("g_hidden");
} else {
Expand Down
5 changes: 5 additions & 0 deletions spec/features/ajax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
response_set = start_survey('Everything')
expect(page).to have_content("What is your favorite color?")
within question("1") do
choose "Other"
find("input[id$='string_value']").set("black")
end
wait_for_ajax
Expand Down Expand Up @@ -186,16 +187,20 @@
click_button "Special"

check "No other heating source"
wait_for_ajax
expect(checkbox("heat2", "neg_1").disabled?).to be_true
expect(checkbox("heat2", "neg_2").disabled?).to be_true

uncheck "No other heating source"
wait_for_ajax
expect(checkbox("heat2", "neg_1").disabled?).to be_false

check "Electric"
wait_for_ajax
expect(checkbox("heat2", "neg_1").disabled?).to be_false

check "Refused"
wait_for_ajax
expect(checkbox("heat2", "1").disabled?).to be_true
expect(checkbox("heat2", "neg_2").disabled?).to be_true
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/wait_for_ajax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ def wait_for_ajax(wait_time = 1)
def finished_all_ajax_requests?
page.evaluate_script('jQuery.active').zero?
end
end
end
6 changes: 3 additions & 3 deletions surveyor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ Gem::Specification.new do |s|
s.add_development_dependency('yard')
s.add_development_dependency('rake')
s.add_development_dependency('sqlite3')
s.add_development_dependency('bundler', '~> 1.6.1')
s.add_development_dependency('bundler', '>= 1.6.1')
s.add_development_dependency('rspec-rails', '~> 2.14.2')
s.add_development_dependency('capybara', '~> 2.2.1')
s.add_development_dependency('launchy', '~> 2.4.2')
s.add_development_dependency('poltergeist', '~>1.5.0')
s.add_development_dependency('json_spec', '~> 1.1.1')
s.add_development_dependency('factory_girl', '~> 4.4.0')
s.add_development_dependency('database_cleaner', '~> 1.2.0')
s.add_development_dependency('rspec-retry')
end
s.add_development_dependency('rspec-retry', '0.4.4')
end