如何创建需要填写的条件字段 [英] How to create conditional fields that are required to be filled out

查看:113
本文介绍了如何创建需要填写的条件字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从其他帖子了解到,我可以使用以下创建一个条件字段:

I learned from other post that I could use the following the create a conditional field:

$('your selects class or id').change(function(){    
    if($(this).val() == "publish_on"){
        $('.secret').fadeIn();
    }
    else{
        $('.secret').hide();
    }
});

从我对此代码的理解中,它只显示/隐藏该字段,而不是实际取消该字段。除非弹出域(.secret)需要成为必填字段,并且我使用表单验证来确保填写所有必填字段,否则这一切都很好。 提交按钮是否自动省略非显示字段?我需要添加进一步的JavaScript,以使它只出现时才需要吗?

From my understanding of this code, it only show/hides the field, instead of actually cancel the field. This is all fine except what if the pop-up field (.secret) needs to be a required field and I use form validation to make sure all required fields are filled out? Does "submit" button omit non-displaying field automatically? Do I need add on further javascript to make it only required when appearing?

推荐答案


是否提交按钮自动省略非显示字段?我需要添加进一步的JavaScript,使它只出现时才需要吗?

Does "submit" button omit non-displaying field automatically? Do I need add on further javascript to make it only required when appearing?

不,它不会省略隐藏的字段。提交它们也是。

No,It doesn't omit the hidden fields.It submit's them too.

你需要在验证时忽略它们。

And you need to omit them while doing validation.

有些东西就像使用可见的seletors

if ( $("#targetEleme").is(":visible") ) {

//then do this validation
}

这篇关于如何创建需要填写的条件字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆