Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Don't set remote_validators_prefix if root_path is not set #515

Merged
merged 1 commit into from

3 participants

@arr-ee

Fixes #513

It's sort of ugly, but it's better than checking it somehow on client side.

Also enabled all the js tests. Hope that's alright.

@coveralls

Coverage remained the same when pulling 372d911 on arr-ee:fix_remote_validations_with_default_root_path into c1b8561 on bcardarella:3-2-stable.

View Details

@bcardarella bcardarella merged commit 8b13b69 into DavyJonesLocker:3-2-stable

1 check passed

Details default The Travis build passed
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.
View
2  lib/client_side_validations/action_view/form_helper.rb
@@ -136,7 +136,7 @@ def client_side_form_settings(object, options)
content_tag(:script) do
- "//<![CDATA[\nif(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=#{ClientSideValidations::Config.disabled_validators.to_json};window.ClientSideValidations.number_format=#{number_format.to_json};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=#{patterns[:numericality]};if(window.ClientSideValidations.remote_validators_prefix===undefined)window.ClientSideValidations.remote_validators_prefix='#{(ClientSideValidations::Config.root_path||"").sub(/\/+\Z/,'')}';if(window.ClientSideValidations.forms===undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['#{var_name}'] = #{builder.client_side_form_settings(options, self).merge(:validators => 'validator_hash').to_json};\n//]]>".html_safe
+ "//<![CDATA[\nif(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=#{ClientSideValidations::Config.disabled_validators.to_json};window.ClientSideValidations.number_format=#{number_format.to_json};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=#{patterns[:numericality]};#{"if(window.ClientSideValidations.remote_validators_prefix===undefined)window.ClientSideValidations.remote_validators_prefix='#{(ClientSideValidations::Config.root_path).sub(/\/+\Z/,'')}';" if ClientSideValidations::Config.root_path.present? }if(window.ClientSideValidations.forms===undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['#{var_name}'] = #{builder.client_side_form_settings(options, self).merge(:validators => 'validator_hash').to_json};\n//]]>".html_safe
end
end
end
View
2  test/action_view/cases/helper.rb
@@ -139,7 +139,7 @@ def whole_form(action = "http://www.example.com", id = nil, html_class = nil, op
def build_script_tag(html, id, validators)
number_format = {:separator => '.', :delimiter => ','}
patterns = {:numericality=>"/^(-|\\+)?(?:\\d+|\\d{1,3}(?:\\#{number_format[:delimiter]}\\d{3})+)(?:\\#{number_format[:separator]}\\d*)?$/"}
- (html || '') + %Q{<script>//<![CDATA[\nif(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=#{ClientSideValidations::Config.disabled_validators.to_json};window.ClientSideValidations.number_format=#{number_format.to_json};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=#{patterns[:numericality]};if(window.ClientSideValidations.remote_validators_prefix===undefined)window.ClientSideValidations.remote_validators_prefix='';if(window.ClientSideValidations.forms===undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['#{id}'] = #{client_side_form_settings_helper.merge(:validators => validators).to_json};\n//]]></script>}
+ (html || '') + %Q{<script>//<![CDATA[\nif(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=#{ClientSideValidations::Config.disabled_validators.to_json};window.ClientSideValidations.number_format=#{number_format.to_json};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=#{patterns[:numericality]};if(window.ClientSideValidations.forms===undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['#{id}'] = #{client_side_form_settings_helper.merge(:validators => validators).to_json};\n//]]></script>}
end
protected
View
3  test/javascript/public/test/utilities.js
@@ -1,7 +1,8 @@
module('Utilities');
test('Remote Validator Url without setting', function() {
- equal(ClientSideValidations.remote_validators_url_for('test'), '//'+window.location.host+'/validators/test');
+ ClientSideValidations.remote_validators_prefix = undefined;
+ equal(ClientSideValidations.remote_validators_url_for('test'), '/validators/test');
});
test('Remote Validator Url with setting', function() {
View
1  test/javascript/public/test/validators/uniqueness.js
@@ -1,5 +1,6 @@
module('Uniqueness options', {
setup: function() {
+ ClientSideValidations.remote_validators_prefix = undefined;
ClientSideValidations.forms['new_user'] = {
type: 'ActionView::Helpers::FormBuilder',
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label class="message"></label></div>',
View
6 test/javascript/views/index.erb
@@ -1,10 +1,10 @@
<% @title = "client_side_validations test" %>
<%= test_base %>
-<%# script_tag 'validateElement' %>
+<%= script_tag 'validateElement' %>
<%= script_tag 'utilities' %>
-<%# test :validators, :form_builders, :callbacks %>
-<%# script_tag 'disableValidators' %>
+<%= test :validators, :form_builders, :callbacks %>
+<%= script_tag 'disableValidators' %>
<h1 id="qunit-header"><%= @title %></h1>
Something went wrong with that request. Please try again.