取消 和 新建 贴吧的按钮都会清空贴吧表单

论坛标题字符长度限定160。是汉字的话只能输入80个
This commit is contained in:
lizanle 2015-09-23 09:11:29 +08:00
parent 7663db693a
commit d6c763edb0
3 changed files with 21 additions and 4 deletions

View File

@ -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

View File

@ -29,5 +29,5 @@
</div>
<div class="creatPost">
<a href="javascript:void(0);" id="create_btn" class="c_white db creatPostIcon bBlue"
onclick="$('#error').hide();$('#new_forum_div').slideToggle();$(this).parent().slideToggle();">新建贴吧</a></div>
onclick="$('#error').hide();clear_form();$('#new_forum_div').slideToggle();$(this).parent().slideToggle();">新建贴吧</a></div>
<div class="cl"></div>

View File

@ -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('');
}