treeborn
Forum Replies Created
-
Hi @sarkparanjothi,
I don’t think this fix made it into the plugin – it gets reverted whenever the plugin is updated.
Could you include it in the future please?
Thanks very much
Thanks very much @sarkparanjothi.
I have implemented your fix and the error and performance issues have been resolved.
…and the event is triggered in a timeout function below that (line 57):
setTimeout(function(){ $( '[data-has_field_rules="yes"]' ).trigger( "change" ); if( wccpf_opt["is_page"] != "archive" ){ self.update_negotiate_price(); } }, 180 );
Great, thankyou! I’ve updated and the field rules now behave as expected.
Thanks again.
Thanks very much for looking in to this, I look forward to the next release.
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.
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)