UX: Improve error messages for minimum and maximum username lengths.

This commit is contained in:
Bianca Nenciu
2018-08-22 21:49:52 +02:00
committed by Guo Xiang Tan
parent 7591da1e64
commit e0d7cdac12
7 changed files with 96 additions and 14 deletions

View File

@@ -0,0 +1,19 @@
class MaxUsernameLengthValidator
def initialize(opts = {})
@opts = opts
end
def valid_value?(value)
return false if value < SiteSetting.min_username_length
@username = User.where('length(username) > ?', value).pluck(:username).first
@username.blank? ? true : false
end
def error_message
if @username.blank?
I18n.t("site_settings.errors.max_username_length_range")
else
I18n.t("site_settings.errors.max_username_length_exists", username: @username)
end
end
end