diff --git a/lib/software_info.rb b/lib/software_info.rb index 1e71eec..f088b29 100644 --- a/lib/software_info.rb +++ b/lib/software_info.rb @@ -14,6 +14,8 @@ class SoftwareInfo < ActiveRecord::Base has_one :software_categories + validates_length_of :finality, :maximum => 100 + # used on find_by_contents scope :like_search, lambda{ |name| joins(:community).where("name ilike ?", "%#{name}%") @@ -92,18 +94,28 @@ class SoftwareInfo < ActiveRecord::Base } } + def validate_name_lenght + if self.community.name.size > 100 + self.errors.add(:base, _("Name is too long (maximum is %{count} characters)")) + false + end + true + end + def validate_operating_platform self.errors.add(:operating_platform, _("can't be blank")) if self.operating_platform.blank? && self.errors.messages[:operating_platform].nil? end def validate_acronym self.acronym = "" if self.acronym.nil? - if self.acronym.length > 10 && self.errors.messages[:acronym].nil? self.errors.add(:acronym, _("can't have more than 10 characteres")) + false elsif self.acronym.match(/\s+/) self.errors.add(:acronym, _("can't have whitespaces")) + false end + true end def valid_operating_systems diff --git a/views/mpog_software_plugin_myprofile/new_software.html.erb b/views/mpog_software_plugin_myprofile/new_software.html.erb index 6d05c3b..81a1581 100644 --- a/views/mpog_software_plugin_myprofile/new_software.html.erb +++ b/views/mpog_software_plugin_myprofile/new_software.html.erb @@ -1,3 +1,4 @@ + <%= javascript_include_tag "mpog-validations" %> <%= stylesheet_link_tag('plugins/mpog_software/mpog-software') %> @@ -29,14 +30,14 @@
<%= environment.default_hostname %>/ - <%= required text_field(:community, :name) %> + <%= required text_field(:community, :name, :size => 30, :maxlength => 100) %> <%= content_tag(:small,_('Insert the name'), :id => 'name-balloon', :class => "helper-balloon") %>
<%= fields_for @software_info do |swf| %>
<%= swf.label("finality" ,_("Finality"), :class=>"formlabel") %> - <%= required swf.text_field(:finality) %> + <%= required swf.text_area(:finality, :cols => 40, :rows => 5, :maxlength => 100) %> <%= content_tag(:small,_('Insert the finality'), :id => 'finality-balloon', :class => "helper-balloon") %>
<% end %> -- libgit2 0.21.2