From d6c763edb08ee151128e58b340d6d3cae6b96571 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Wed, 23 Sep 2015 09:11:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=20=20=E5=92=8C=20=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=20=E8=B4=B4=E5=90=A7=E7=9A=84=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E9=83=BD=E4=BC=9A=E6=B8=85=E7=A9=BA=E8=B4=B4=E5=90=A7=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=20=E8=AE=BA=E5=9D=9B=E6=A0=87=E9=A2=98=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E9=95=BF=E5=BA=A6=E9=99=90=E5=AE=9A160=E3=80=82?= =?UTF-8?q?=E6=98=AF=E6=B1=89=E5=AD=97=E7=9A=84=E8=AF=9D=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E8=BE=93=E5=85=A580=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/forum.rb | 2 +- app/views/forums/_post_banner.html.erb | 2 +- app/views/forums/index.html.erb | 21 +++++++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/models/forum.rb b/app/models/forum.rb index 530639f81..9fa1b7dfd 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -14,7 +14,7 @@ class Forum < ActiveRecord::Base 'sticky', 'locked' validates_presence_of :name, :creator_id, :description - validates_length_of :name, maximum: 50 + validates_length_of :name, maximum: 160 #validates_length_of :description, maximum: 255 validates :name, :uniqueness => true after_destroy :delete_kindeditor_assets diff --git a/app/views/forums/_post_banner.html.erb b/app/views/forums/_post_banner.html.erb index 2ea128e9d..797b43245 100644 --- a/app/views/forums/_post_banner.html.erb +++ b/app/views/forums/_post_banner.html.erb @@ -29,5 +29,5 @@
+ onclick="$('#error').hide();clear_form();$('#new_forum_div').slideToggle();$(this).parent().slideToggle();">新建贴吧 \ No newline at end of file diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index f7c74e9a7..aeb0e1654 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -49,7 +49,21 @@ $("#reorder_popu").removeClass("sortArrowActiveD"); add_class("reorder_time"); }); - + document.getElementById('forum_name').onkeydown = function() + { + var n = 0; + var str = this.value; + for (i = 0; i < str.length; i++) { + var leg = str.charCodeAt(i);//ASCII码 + if (leg > 255) {//大于255的都是中文 + n += 2;//如果是中文就是2个字节 + } else { + n += 1;//英文,不多说了 + } + } + if(n >= 160) + event.returnValue = false; + } }); function check_and_submit(doc){ $("#error").html('').hide(); @@ -88,6 +102,9 @@ $('#error').hide(); $('#new_forum_div').slideToggle(); $('#create_btn').parent().slideToggle(); + clear_form(); + } + function clear_form(){ $("#forum_name").val(''); $("#forum_desc").val(''); } @@ -100,7 +117,7 @@ <%= form_tag({:controller => 'forums',:action=>'create',:format=>'js'},:method => 'post',:remote=>'true') do |f| %>