Support » Plugin: WC Fields Factory » Only first Field Rule obeyed, additional ones ignored / fields remain hidden

  • Resolved treeborn

    (@treeborn)


    I am using multiple select inputs on a single product page.

    If the customer wants the product ‘framed’ or ‘framed and mounted’ for example, additional options are shown.

    There are two rules for this field, but an additional field is only shown when the first rule is true. It remains hidden even when the second rule’s conditions are met.

    I have tried this with several select fields and in each case, only the first rule is checked, the rest are ignored.

    thanks,

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author sarkparanjothi

    (@sarkparanjothi)

    You should use initial field show or hidden.
    And try to get knowledge about nil condition on fields rule.

    Thanks for your reply. The three additional select fields are hidden on load. They should be revealed conditionally.

    There are three rules for the field, and I have tried various combinations of ‘hide’,’show’ and ‘nil’ for each. Please see below for the rules, expected output, and the actual output.

    what I expect to see:
    if select 1 = option a show select 2 (field rules: show select 2, hide select 3, hide select 4)
    if select 1 = option b show select 3 (field rules: select 2 nil, show select 3, select 4 nil)
    if select 1 = option c show select 4 (field rules: select 2 nil, select 3 nil, show select 4)
    
    select 2, select 3 and select 4 are all hidden on load
    
    what I actually see:
    select 1 = option a, select 2 is shown (others are hidden)
    select 1 = option b, select 3 and 4 are shown (2,4 should be hidden)
    select 1 = option c, select 3 and 4 are shown (2,3 should be hidden)
    
    what I expect to see:
    if select 1 = option a show select 2 (field rules: show select 2, select 3 nil, select 4 nil)
    if select 1 = option b show select 3 (field rules: select 2 nil, show select 3, select 4 nil)
    if select 1 = option c show select 4 (field rules: select 2 nil, select 3 nil, show select 4)
    
    select 2, select 3 and select 4 are all hidden on load
    
    what I actually see:
    select 1 = option a, select 2 is shown (others are hidden)
    select 1 = option b, select 2,3,4 hidden (2 should be visible)
    select 1 = option c, select 2,3,4 hidden (4 should be visible)
    
    what I expect to see:
    if select 1 = option a show select 2 (field rules: show select 2, hide select 3, hide select 4)
    if select 1 = option b show select 3 (field rules: hide select 2, show select 3, hide select 4)
    if select 1 = option c show select 4 (field rules: hide select 2, hide select 3, show select 4)
    
    select 2, select 3 and select 4 are all hidden on load
    
    what I actually see:
    select 1 = option a, select 2 is shown (others are hidden)
    select 1 = option b, select 3,4 visible (only 3 should be visible)
    select 1 = option c, select 3,4 visible (only 4 should be visible)
    
    what I expect to see:
    if select 1 = option a show select 2 (field rules: show select 2, hide select 3, select 4 nil)
    if select 1 = option b show select 3 (field rules: select 2 nil, show select 3, select 4 nil)
    if select 1 = option c show select 4 (field rules: select 2 nil, select 3 nil, show select 4)
    
    select 2, select 3 and select 4 are all hidden on load
    
    what I actually see:
    select 1 = option a, select 2 is shown (others are hidden)
    select 1 = option b, select 3 visible
    select 1 = option c, select 3 visible (only select 4 should be visible)
    WordPress

    (@alcatraztours)

    I am Facing the same problem.

    Same problem here. It does not matter if fields are hidden or visible when loading. For more than one condition or more complex dependencies, only the first condition applies.

    I really appreciate the good and intense work for this great plugin. Well thought out, very clear and well documented. That’s why I decided to use this plugin.

    But if I get to logic conditioning after hours of configuring the fields and customizing the styles, that feature just has to work just fine. Especially if this plugin is offered for the WordPress community and productive application.

    This essential function must be fixed, then I can give a rating. I would not have liked to waste my time on this good plugin and use another one instead.

    • This reply was modified 1 year, 2 months ago by discobrille.

    Update:

    Before I made further product attribute adjustments with this plugin, I first tested the further functionality.

    The result (for me) is that I can not continue using WC Fields Factory.

    Even the shopping cart update is not working properly. If I delete an item, the badge is counted down, but if the page updates or adds another item, the deleted items are back in the cart. Also duplicates. Due to time constraints, I can not offer a detailed reproduction report here.

    After switching off the plug-in, the shopping cart management works correctly.

    Bye for now.

    • This reply was modified 1 year, 2 months ago by discobrille.

    Just to update you @sarkparanjothi, it seems as the problem lies in the jQuery code generated by the field_rules_script_render method in the negotiator class.

    This is the generated code:

     var $ = jQuery;
    													jQuery(document).ready(function(){ 
    														jQuery(document).on("change", "[data-has_field_rules=yes]", function(){
    															var field_name = jQuery(this).attr( "name" ), clone_index = false ? field_name.slice( field_name.lastIndexOf("_"),  field_name.length ) : "";if(false){}else if(jQuery(this).attr("name") == "include_names"+clone_index+"" ){
        							if( jQuery(this).val() == "yes" ){jQuery( "[name='select_test"+clone_index+"']" ).closest(".wccpf_fields_table").show().removeClass("wcff_is_hidden_from_field_rule");} else {jQuery( "[name='select_test"+clone_index+"']" ).closest(".wccpf_fields_table").hide().addClass("wcff_is_hidden_from_field_rule");} }var field_name = jQuery(this).attr( "name" ), clone_index = false ? field_name.slice( field_name.lastIndexOf("_"),  field_name.length ) : "";if(false){}else if(jQuery(this).attr("name") == "select_1"+clone_index+"" ){
        							if( jQuery(this).val() == "a" ){jQuery( "[name='select_2"+clone_index+"']" ).closest(".wccpf_fields_table").show().removeClass("wcff_is_hidden_from_field_rule");} else {jQuery( "[name='select_2"+clone_index+"']" ).closest(".wccpf_fields_table").hide().addClass("wcff_is_hidden_from_field_rule");} }else if(jQuery(this).attr("name") == "portrait_size"+clone_index+"" ){
        							if( jQuery(this).val() == "b" ){jQuery( "[name='select_3"+clone_index+"']" ).closest(".wccpf_fields_table").show().removeClass("wcff_is_hidden_from_field_rule");} else {jQuery( "[name='select_3"+clone_index+"']" ).closest(".wccpf_fields_table").hide().addClass("wcff_is_hidden_from_field_rule");} }else if(jQuery(this).attr("name") == "portrait_size"+clone_index+"" ){
        							if( jQuery(this).val() == "c" ){jQuery( "[name='select_4"+clone_index+"']" ).closest(".wccpf_fields_table").show().removeClass("wcff_is_hidden_from_field_rule");} else {jQuery( "[name='select_4"+clone_index+"']" ).closest(".wccpf_fields_table").hide().addClass("wcff_is_hidden_from_field_rule");} }});
    										});
    									

    Each option / condition that we check for an input is wrapped in if / else if statements:

    } else if (jQuery(this).attr("name") == "select_1" + clone_index + "") {

    As the condition “select_1” is true for the first check, subsequent ‘else if’s are not going to get called.

    Putting the conditions / values in one ‘if’ statement gives the expected hide / show behaviour for my case.

    The manually adjusted output looks like this:

    var $ = jQuery;
     jQuery(document).ready(function() {
       
         jQuery(document).on("change", "[data-has_field_rules=yes]", function() {
           
           
             var field_name = jQuery(this).attr("name"),
                 clone_index = false ? field_name.slice(field_name.lastIndexOf("_"), field_name.length) : "";
             if (false) {} else if (jQuery(this).attr("name") == "include_names" + clone_index + "") {
                 if (jQuery(this).val() == "yes") {
                     jQuery("[name='select_test" + clone_index + "']").closest(".wccpf_fields_table").show().removeClass("wcff_is_hidden_from_field_rule");
                 } else {
                     jQuery("[name='select_test" + clone_index + "']").closest(".wccpf_fields_table").hide().addClass("wcff_is_hidden_from_field_rule");
                 }
             }
           
             var field_name = jQuery(this).attr("name"),
                 clone_index = false ? field_name.slice(field_name.lastIndexOf("_"), field_name.length) : "";
             if (false) {} else if (jQuery(this).attr("name") == "select_1" + clone_index + "") {
                 if (jQuery(this).val() == "a") {
                     jQuery("[name='select_2" + clone_index + "']").closest(".wccpf_fields_table").show().removeClass("wcff_is_hidden_from_field_rule");
                 } else {
                     jQuery("[name='select_2" + clone_index + "']").closest(".wccpf_fields_table").hide().addClass("wcff_is_hidden_from_field_rule");
                 }
            
                 if (jQuery(this).val() == "b") {
                     jQuery("[name='select_3" + clone_index + "']").closest(".wccpf_fields_table").show().removeClass("wcff_is_hidden_from_field_rule");
                 } else {
                     jQuery("[name='select_3" + clone_index + "']").closest(".wccpf_fields_table").hide().addClass("wcff_is_hidden_from_field_rule");
                 }
             
                 if (jQuery(this).val() == "c") {
                     jQuery("[name='select_4" + clone_index + "']").closest(".wccpf_fields_table").show().removeClass("wcff_is_hidden_from_field_rule");
                 } else {
                     jQuery("[name='select_4" + clone_index + "']").closest(".wccpf_fields_table").hide().addClass("wcff_is_hidden_from_field_rule");
                 }
             }
         
         
         });
     
     
     });

    Pasting that in the console to test gave me the expected behaviour of the select inputs’ visibility.

    So, I think the code that generates the jQuery output (in the negotiator class) needs adjusting to not put each condition / field rule in it’s own ‘else if’, just one for all the rules for a particular field.

    Plugin Author sarkparanjothi

    (@sarkparanjothi)

    hi @treeborn,
    Thank you for your brief explanation.

    HI @treeborn,
    But still i having little confusion can you share your admin field rule screenshot.

    Thanks

    Plugin Author sarkparanjothi

    (@sarkparanjothi)

    Hi @treeborn, i changed field rule what you explain on my working copy. I hope @treeborn will be close. so please wait wcff next relase (3.0.2)

    Thanks very much for looking in to this, I look forward to the next release.

    Plugin Author sarkparanjothi

    (@sarkparanjothi)

    HI @treeborn,
    Please take update wcff v(3.0.2)

    Great, thankyou! I’ve updated and the field rules now behave as expected.

    Thanks again.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Only first Field Rule obeyed, additional ones ignored / fields remain hidden’ is closed to new replies.