【问题标题】:Woocommerce - Jquery | Remove the required attribute from some checkout input fields based on the selection from a select fieldWoocommerce - Jquery |根据从选择字段中的选择,从某些结帐输入字段中删除必需的属性
【发布时间】:2020-01-03 12:40:32
【问题描述】:

大家好,我正在处理我下载的插件的代码,目标是根据用户的选择隐藏 Woocommerce 结算结帐表单的某些字段,创建此插件的开发人员已实现一个名为:billing_invoice_type 的可选字段,然后是一个 if 循环,它承认当这个字段等于一个值时,必须生成一些东西的各种可能性,此时我已经实现了能够隐藏字段的指令我感兴趣的:

var wcpdf_IT;
function wcpdf_IT_billing_customer_type_change(wcpdf_IT_country_selected) {
    jQuery("#billing_cf_field label").html(wcpdf_IT.lblCommon);
    jQuery("#billing_cf").attr("placeholder", wcpdf_IT.txtCommon);
    if(jQuery("#billing_invoice_type").val() === "receipt" ) {

        // RIMUOVI LABEL E CAMPO INPUT | NOME DELLA SOCIETÀ
        jQuery("#billing_company_field ").hide();

        // RIMUOVI LABEL E CAMPO INPUT | CAP
        jQuery("#billing_postcode_field ").hide();

        // RIMUOVI LABEL E CAMPO INPUT | INDIRIZZO
        jQuery("#billing_address_1_field ").hide();

        // RIMUOVI LABEL E CAMPO INPUT | APPARTAMENTO / SUITE
        jQuery("#billing_address_2_field ").hide();

        // RIMUOVI LABEL E CAMPO INPUT | CITTÀ
        jQuery("#billing_city_field ").show();
        $('#billing_city').removeClass('woocommerce-invalid woocommerce-invalid-required-field');


        // RIMUOVI LABEL E CAMPO INPUT | PROVINCIA
        jQuery("#billing_state_field ").hide();


        jQuery("#billing_cf_field label").html(wcpdf_IT.lblPersonal);
        jQuery("#billing_cf").attr("placeholder", wcpdf_IT.txtPersonal);
    }
    wcpdf_IT_check_PEC();
}

然而,现在的问题不仅仅是让它们出现或隐藏,而是这些默认字段是必需的类型,因此用户在编译阶段看不到它们,但是当他完成编译时出现错误显示在显示屏上是因为他必须填写隐藏字段,所以我必须删除所需的属性。

我尝试了多种方式,通过 Jquery 从我感兴趣但尝试失败的字段中删除了必需的属性。

我该怎么办?

【问题讨论】:

  • 你有解决办法吗?如果是,请在此处分享。

标签: jquery wordpress woocommerce


【解决方案1】:

你试过$('your_elem').removeAttr('required')吗?

这应该可行。

【讨论】:

  • 如果我尝试://RIMUOVI LABEL E CAMPO INPUT | CITTÀ jQuery("#billing_city_field ").show(); $('#billing_city_field').removeAttr('required'); ---> 不工作
【解决方案2】:

我不确定这是否适用于您的情况,但您可以尝试一下 RIMUOVI LABEL E CAMPO 输入 | NOME DELLA SOCIETÀ

jQuery("#billing_company_field").hide(function(){

    jQuery(this).removeClass("validate-required");
    jQuery(this).removeClass("woocommerce-validated");
    jQuery('#billing_company').val("no");

});

【讨论】:

    猜你喜欢
    • 2023-01-26
    • 2011-10-28
    • 1970-01-01
    • 2012-04-07
    • 2015-10-10
    • 2023-04-06
    • 2018-11-19
    • 1970-01-01
    • 2018-05-24
    相关资源
    最近更新 更多