Permalink
Browse files

Switched to same convention as Validatious with namespaces in lowerca…

…se: v2.Rails => v2.rails.
  • Loading branch information...
1 parent 2e41b78 commit f07895df01bb6cfdffe2694b25caa7de23dce007 @grimen grimen committed Oct 31, 2009
View
@@ -2,12 +2,12 @@ h1. CHANGELOG
h2. 0.4.8
-* bug-fix: Removed debug line in @v2.Rails.js@ that will cause headache in non-Webkit browsers.
+* bug-fix: Removed debug line in @v2.rails.js@ that will cause headache in non-Webkit browsers.
* bug-fix: Duplication of validation declarations is now ignored, only first ones is used. No more infinite AJAX-requests caused by this.
h2. 0.4.7
-* refactor: DRYed up @v2.Rails.js@ a bit, with help of new method: @v2.present()@.
+* refactor: DRYed up @v2.rails.js@ a bit, with help of new method: @v2.present()@.
* enhancement: @validates_uniqueness_of@ (or remote validations) implements allow_nil/allow_blank on client-side to avoid flickering validation messages, and unnecessary requests. They are both very fundamental input validation features so this makes sense, but of course this is easy to override in the future for custom validations but should work great for 9/10 cases at least.
* bug-fix: remote-client (remote validations substitution validator) now got @acceptEmpty@ set to false, because set to true cause remote validators to flicker a fail message on first attempt if the field is empty.
* bug-fix: @validates_uniqueness_of@-message now uses the correct I18n key (@:blank@ => @:taken@)
@@ -2,10 +2,10 @@
* Helpers for Validatious-On-Rails, mostly related to remote validations.
*/
-if (typeof v2.Rails === 'undefined' || v2.Rails === null) {
- v2.Rails = {};
- v2.Rails.params = {};
- v2.Rails.messages = {};
+if (typeof v2.rails === 'undefined' || v2.rails === null) {
+ v2.rails = {};
+ v2.rails.params = {};
+ v2.rails.messages = {};
}
/**
@@ -56,18 +56,18 @@ v2.Validator.add({acceptEmpty: false, fn: function(field, value, params) { retur
/**
* Perform a remote validation on a given field the Validatious way, slightly modified
*/
- v2.Rails.performRemoteValidation = function performRemoteValidation(name, field, value, params, message) {
+ v2.rails.performRemoteValidation = function performRemoteValidation(name, field, value, params, message) {
var field_element = field.__elements[0];
- var url = v2.Rails.remoteValidationUrlFor(name, field_element, value, []);
+ var url = v2.rails.remoteValidationUrlFor(name, field_element, value, []);
- v2.Rails.initializeLastResult(name, field_element.id);
+ v2.rails.initializeLastResult(name, field_element.id);
var xmlHttpRequest = new XMLHttpRequest;
xmlHttpRequest.open('GET', url, true);
xmlHttpRequest.onreadystatechange = function() {
if (this.readyState == XMLHttpRequest.DONE) {
var validationResult = v2.bool(this.responseText);
- v2.Rails.lastRemoteValidationResult[name][field_element.id] = validationResult;
+ v2.rails.lastRemoteValidationResult[name][field_element.id] = validationResult;
/* Get all validators for this field, except the current validator. */
var fieldClasses = v2.trim(field_element.getAttribute('class').replace(new RegExp(name + '\w*'), ''));
@@ -82,22 +82,22 @@ v2.Validator.add({acceptEmpty: false, fn: function(field, value, params) { retur
};
};
xmlHttpRequest.send(null);
- return v2.Rails.lastRemoteValidationResult[name][field_element.id];
+ return v2.rails.lastRemoteValidationResult[name][field_element.id];
};
/**
* Initialize data structure for holding info about last remote AJAX validation result.
* We need this to make Validatious play well with remote validations.
*/
- v2.Rails.initializeLastResult = function initializeLastResult(validator_name, field_id) {
- if (!v2.present(v2.Rails.lastRemoteValidationResult)) {
- v2.Rails.lastRemoteValidationResult = new Array();
+ v2.rails.initializeLastResult = function initializeLastResult(validator_name, field_id) {
+ if (!v2.present(v2.rails.lastRemoteValidationResult)) {
+ v2.rails.lastRemoteValidationResult = new Array();
};
- if (!v2.present(v2.Rails.lastRemoteValidationResult[validator_name])) {
- v2.Rails.lastRemoteValidationResult[validator_name] = new Array();
+ if (!v2.present(v2.rails.lastRemoteValidationResult[validator_name])) {
+ v2.rails.lastRemoteValidationResult[validator_name] = new Array();
};
- if (!v2.present(v2.Rails.lastRemoteValidationResult[validator_name][field_id])) {
- v2.Rails.lastRemoteValidationResult[validator_name][field_id] = false;
+ if (!v2.present(v2.rails.lastRemoteValidationResult[validator_name][field_id])) {
+ v2.rails.lastRemoteValidationResult[validator_name][field_id] = false;
};
};
@@ -108,10 +108,10 @@ v2.Validator.add({acceptEmpty: false, fn: function(field, value, params) { retur
* Example:
* /validates/uniqueness_of?model=article&attribute=title(&id=2)&value=Lorem&params[0]=334&params[1]=hello&...
*/
-v2.Rails.remoteValidationUrlFor = function remoteValidationUrlFor(name, field, value, params) {
- var modelName = v2.Rails.modelNameByField(field);
- var attributeName = v2.Rails.attributeNameByField(field);
- var recordId = v2.Rails.recordIdByField(field);
+v2.rails.remoteValidationUrlFor = function remoteValidationUrlFor(name, field, value, params) {
+ var modelName = v2.rails.modelNameByField(field);
+ var attributeName = v2.rails.attributeNameByField(field);
+ var recordId = v2.rails.recordIdByField(field);
var paramsString = new Array(params.length);
for (var i = 0; i < params.length; i++) {
paramsString[i] = 'params[' + i + ']=' + escape(params[i]);
@@ -131,7 +131,7 @@ v2.Rails.remoteValidationUrlFor = function remoteValidationUrlFor(name, field, v
/**
* Get form containing a specified field.
*/
-v2.Rails.formByField = function formByField(field) {
+v2.rails.formByField = function formByField(field) {
var parent = field.parentNode;
while((parent.tagName != 'FORM')) { parent = parent.parentNode; }
return parent;
@@ -141,24 +141,24 @@ v2.Rails.formByField = function formByField(field) {
* form_element.id="edit_account_34" => 34
* form_element.id="new_account" => nil
*/
-v2.Rails.recordIdByField = function recordIdByField(field) {
- var form = v2.Rails.formByField(field);
+v2.rails.recordIdByField = function recordIdByField(field) {
+ var form = v2.rails.formByField(field);
var recordId = form.id.match(/(\d+)$/);
return (recordId && recordId.length > 1) ? +recordId[1] : null;
};
/**
* field_element.name="account[login]" => 'account'
*/
-v2.Rails.modelNameByField = function modelNameByField(field) {
+v2.rails.modelNameByField = function modelNameByField(field) {
var modelName = field.name.match(/^(.*)\[.*\]$/);
return (modelName.length > 1) ? modelName[1] : '';
};
/**
* field_element.name="account[login]" => 'login'
*/
-v2.Rails.attributeNameByField = function attributeNameByField(field) {
+v2.rails.attributeNameByField = function attributeNameByField(field) {
var attributeName = field.name.match(/^.*\[(.*)\]$/);
return (attributeName.length > 1) ? attributeName[1] : '';
};
@@ -20,7 +20,7 @@ def fn
value += '';
#{self.class.handle_nil(0)}
#{self.class.handle_blank(1)}
- return v2.Rails.performRemoteValidation(#{self.name.to_json}, field, value, params, #{self.message.to_json});
+ return v2.rails.performRemoteValidation(#{self.name.to_json}, field, value, params, #{self.message.to_json});
}
})
end
@@ -12,12 +12,12 @@ def initialize(*args)
self.message = self.class.generate_message(:exclusion)
self.params = %w[exclude allow_nil allow_blank]
self.data = %{
- v2.Rails.params['#{args.first}'] = #{data.to_json};
+ v2.rails.params['#{args.first}'] = #{data.to_json};
}
self.fn = %{
#{self.class.handle_nil(1)}
#{self.class.handle_blank(2)}
- var exclusion_values = v2.Rails.params[params[0]];
+ var exclusion_values = v2.rails.params[params[0]];
for (var i = 0; i < exclusion_values.length; i++) {
if (exclusion_values[i] == value) { return false; }
};
@@ -12,13 +12,13 @@ def initialize(*args)
self.message = self.class.generate_message(:invalid)
self.params = %w[format allow_nil allow_blank]
self.data = %{
- v2.Rails.params['#{args.first}'] = #{data.inspect.gsub(/\\A/, '^').gsub(/\\z/, '$')};
+ v2.rails.params['#{args.first}'] = #{data.inspect.gsub(/\\A/, '^').gsub(/\\z/, '$')};
}
- # v2.Rails.messages['#{args.first}'] = #{self.message.to_json};
+ # v2.rails.messages['#{args.first}'] = #{self.message.to_json};
self.fn = %{
#{self.class.handle_nil(1)}
#{self.class.handle_blank(2)}
- return v2.Rails.params[params[0]].test(value);
+ return v2.rails.params[params[0]].test(value);
}
end
@@ -12,12 +12,12 @@ def initialize(*args)
self.message = self.class.generate_message(:inclusion)
self.params = %w[include allow_nil allow_blank]
self.data = %{
- v2.Rails.params['#{args.first}'] = #{data.to_json};
+ v2.rails.params['#{args.first}'] = #{data.to_json};
}
self.fn = %{
#{self.class.handle_nil(1)}
#{self.class.handle_blank(2)}
- var inclusion_values = v2.Rails.params[params[0]];
+ var inclusion_values = v2.rails.params[params[0]];
for (var i = 0; i < inclusion_values.length; i++) {
if (inclusion_values[i] == value) { return true; }
};

0 comments on commit f07895d

Please sign in to comment.