mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Word limit on user biography changes
This commit is contained in:
parent
e082e7599d
commit
22916971c7
2 changed files with 16 additions and 4 deletions
|
|
@ -1,5 +1,17 @@
|
|||
$(function () {
|
||||
|
||||
/**
|
||||
* Show the number of words in the biography text field when opening the
|
||||
* profile edit page
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
word_count($("#user_biography")[0], 'bio_length', 150);
|
||||
});
|
||||
|
||||
/**
|
||||
* Update the number of words in the biography text field every time the user
|
||||
* releases a key on the keyboard
|
||||
*/
|
||||
$("#user_biography").bind('keyup', function() {
|
||||
word_count(this, 'bio_length', 150);
|
||||
} );
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ class User < ActiveRecord::Base
|
|||
},
|
||||
presence: true
|
||||
|
||||
validate :check_biography_length
|
||||
|
||||
validate :biography_limit
|
||||
|
||||
def attended_event? event
|
||||
event_registration = event.events_registrations.find_by(registration: self.registrations)
|
||||
|
||||
|
|
@ -190,9 +190,9 @@ class User < ActiveRecord::Base
|
|||
##
|
||||
# Check if biography has an allowed number of words. Used as validation.
|
||||
#
|
||||
def check_biography_length
|
||||
def biography_limit
|
||||
if self.biography.present?
|
||||
errors.add(:biography, 'is limited to 150 words.') unless self.biography.split.length <= 150
|
||||
errors.add(:biography, 'is limited to 150 words.') if self.biography.split.length > 150
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue