Skip to content

Instantly share code, notes, and snippets.

@guoxiangke
Last active August 26, 2017 05:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guoxiangke/8643863 to your computer and use it in GitHub Desktop.
Save guoxiangke/8643863 to your computer and use it in GitHub Desktop.
1.drupal 7,表单如果有必填项没有填写,提交的话,自动focus到未填项。
//form behaviors
$('form .form-submit').click(function(e){
$('input.required').each(function(){
if($(this).val()==''){
$(this).focus();
e.preventDefault()
return false;
}
});
});
//默认隐藏注册表单描述,点击显示
$('#user-register-form .form-type-textfield .description').hide();
$('#user-register-form .form-type-textfield ').click(function(){
$(this).children('.description').show();
});
$('#user-register-form .form-type-textfield input').blur(function(){
var warning_str = '必须填写'+$(this).prev('label').text().replace('*','');
if($(this).val() == '' && $(this).hasClass('required')) {
$(this).parent('.form-type-textfield').children('.description').text(warning_str);
}else{
$(this).parent('.form-type-textfield').children('.description').hide();
};
});
//username min length 2
$('#user-register-form input.username').blur(function(){
if($(this).val().length<2) {
if(confirm('用户名至少2个字符')){
$(this).focus();
};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment