Converted invalid_chars validator to use locale
This commit is contained in:
parent
3b68061e87
commit
e091246ffc
5 changed files with 8 additions and 7 deletions
|
@ -2,6 +2,6 @@ class InvalidCharsValidator < ActiveModel::EachValidator
|
||||||
INVALID_CHARS = "\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff".freeze
|
INVALID_CHARS = "\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff".freeze
|
||||||
|
|
||||||
def validate_each(record, attribute, value)
|
def validate_each(record, attribute, value)
|
||||||
record.errors[attribute] << (options[:message] || "contains invalid chars") if value =~ /[#{INVALID_CHARS}]/
|
record.errors[attribute] << (options[:message] || I18n.t("validations.invalid_chars")) if value =~ /[#{INVALID_CHARS}]/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,6 @@ class InvalidUrlCharsValidator < ActiveModel::EachValidator
|
||||||
INVALID_URL_CHARS = "/;.,?%#".freeze
|
INVALID_URL_CHARS = "/;.,?%#".freeze
|
||||||
|
|
||||||
def validate_each(record, attribute, value)
|
def validate_each(record, attribute, value)
|
||||||
record.errors[attribute] << (options[:message] || I18n.t("validations.invalid chars", :invalid_chars => INVALID_URL_CHARS)) if value =~ /[#{INVALID_URL_CHARS}]/
|
record.errors[attribute] << (options[:message] || I18n.t("validations.invalid_url_chars", :invalid_url_chars => INVALID_URL_CHARS)) if value =~ /[#{INVALID_URL_CHARS}]/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class LeadingWhitespaceValidator < ActiveModel::EachValidator
|
class LeadingWhitespaceValidator < ActiveModel::EachValidator
|
||||||
def validate_each(record, attribute, value)
|
def validate_each(record, attribute, value)
|
||||||
record.errors[attribute] << (options[:message] || I18n.t("validations.leading whitespace")) if value =~ /\A\s/
|
record.errors[attribute] << (options[:message] || I18n.t("validations.leading_whitespace")) if value =~ /\A\s/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class TrailingWhitespaceValidator < ActiveModel::EachValidator
|
class TrailingWhitespaceValidator < ActiveModel::EachValidator
|
||||||
def validate_each(record, attribute, value)
|
def validate_each(record, attribute, value)
|
||||||
record.errors[attribute] << (options[:message] || I18n.t("validations.trailing whitespace")) if value =~ /\s\z/
|
record.errors[attribute] << (options[:message] || I18n.t("validations.trailing_whitespace")) if value =~ /\s\z/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2563,6 +2563,7 @@ en:
|
||||||
flash: "Redaction destroyed."
|
flash: "Redaction destroyed."
|
||||||
error: "There was an error destroying this redaction."
|
error: "There was an error destroying this redaction."
|
||||||
validations:
|
validations:
|
||||||
leading whitespace: "has leading whitespace"
|
leading_whitespace: "has leading whitespace"
|
||||||
trailing whitespace: "has trailing whitespace"
|
trailing_whitespace: "has trailing whitespace"
|
||||||
invalid chars: "must not contain an invalid char: %{invalid_chars}"
|
invalid_chars: "contains invalid chars"
|
||||||
|
invalid_url_chars: "must not contain an invalid char: %{invalid_url_chars}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue