From c041fe4d86dd5cebf504fcc8cd89536ae58b6952 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Tue, 30 Jan 2024 17:44:11 +0530 Subject: [PATCH 1/4] `gw-prevent-duplicate-selections.php`: Fixed an issue with duplicate selections logic did not work with some dynamically populated data. --- gravity-forms/gw-prevent-duplicate-selections.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gravity-forms/gw-prevent-duplicate-selections.php b/gravity-forms/gw-prevent-duplicate-selections.php index 32640fe36..91dda0369 100644 --- a/gravity-forms/gw-prevent-duplicate-selections.php +++ b/gravity-forms/gw-prevent-duplicate-selections.php @@ -47,7 +47,7 @@ public function output_script() { Date: Thu, 1 Feb 2024 12:47:06 +0530 Subject: [PATCH 2/4] `gw-prevent-duplicate-selections.php`: Fixed an issue with duplicate selections logic did not work with some dynamically populated data. --- .../gw-prevent-duplicate-selections.php | 51 ++++++++++++------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/gravity-forms/gw-prevent-duplicate-selections.php b/gravity-forms/gw-prevent-duplicate-selections.php index 91dda0369..7a8c2a329 100644 --- a/gravity-forms/gw-prevent-duplicate-selections.php +++ b/gravity-forms/gw-prevent-duplicate-selections.php @@ -22,7 +22,7 @@ * Author URI: http://gravitywiz.com */ -class GW_Prevent_Duplicate_Selections { + class GW_Prevent_Duplicate_Selections { public function __construct() { // do version check in the init to make sure if GF is going to be loaded, it is already loaded add_action( 'init', array( $this, 'init' ) ); @@ -30,6 +30,7 @@ public function __construct() { public function init() { add_filter( 'gform_pre_render', array( $this, 'load_form_script' ), 10, 2 ); + add_action( 'gform_register_init_scripts', array( $this, 'add_init_script' ), 10, 2 ); } public function load_form_script( $form, $is_ajax_enabled ) { @@ -42,25 +43,45 @@ public function load_form_script( $form, $is_ajax_enabled ) { return $form; } + public function add_init_script( $form ) { + if ( ! $this->is_applicable_form( $form ) ) { + return; + } + + $args = array(); + + $script = 'new ' . __CLASS__ . '( ' . json_encode( $args ) . ' );'; + $slug = implode( '_', array( strtolower( __CLASS__ ) ) ); + + GFFormDisplay::add_init_script( $form['id'], $slug, GFFormDisplay::ON_PAGE_RENDER, $script ); + } + public function output_script() { ?> - Date: Thu, 1 Feb 2024 12:47:50 +0530 Subject: [PATCH 3/4] `gw-prevent-duplicate-selections.php`: Fixed an issue with duplicate selections logic did not work with some dynamically populated data. --- gravity-forms/gw-prevent-duplicate-selections.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-forms/gw-prevent-duplicate-selections.php b/gravity-forms/gw-prevent-duplicate-selections.php index 7a8c2a329..1fae026f2 100644 --- a/gravity-forms/gw-prevent-duplicate-selections.php +++ b/gravity-forms/gw-prevent-duplicate-selections.php @@ -22,7 +22,7 @@ * Author URI: http://gravitywiz.com */ - class GW_Prevent_Duplicate_Selections { +class GW_Prevent_Duplicate_Selections { public function __construct() { // do version check in the init to make sure if GF is going to be loaded, it is already loaded add_action( 'init', array( $this, 'init' ) ); From ce2304e02fc39136a975c93036b56256669749cb Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Thu, 8 Feb 2024 19:57:20 +0530 Subject: [PATCH 4/4] `gw-prevent-duplicate-selections.php`: Fixed an issue with duplicate selections logic did not work with some dynamically populated data. --- .../gw-prevent-duplicate-selections.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/gravity-forms/gw-prevent-duplicate-selections.php b/gravity-forms/gw-prevent-duplicate-selections.php index 1fae026f2..c88d44b7e 100644 --- a/gravity-forms/gw-prevent-duplicate-selections.php +++ b/gravity-forms/gw-prevent-duplicate-selections.php @@ -77,6 +77,26 @@ public function output_script() { gwDisableDuplicates( $( this ), $( '.gw-prevent-duplicates' ).find( 'input, select' ), selected ); } ); + // Event listener for post conditional logic + $(document).on('gform_post_conditional_logic', function(event, formId, fields, isInit){ + // Check each field affected by conditional logic + $.each(fields, function(index, fieldId){ + var $field = $('#field_' + formId + '_' + fieldId); + var $inputs = $field.find('input, select'); + + // Check if the field contains input/select elements and if has been hidden or is now visible + if($inputs.length > 0 && $field.is(':hidden') ){ + // Field has been hidden + $('.gw-disable-duplicates-disabled').removeClass('gw-disable-duplicates-disabled gf-default-disabled').prop('disabled', false); + gwDisableDuplicates($inputs, $('.gw-prevent-duplicates').find('input, select').not($field.find('input, select'))); + } + if($inputs.length > 0 && ! $field.is(':hidden') ){ + // Field has been shown + gwDisableDuplicates($inputs, $('.gw-prevent-duplicates').find('input, select')); + } + }); + }); + // Handle on-load $inputs = $( '.gw-prevent-duplicates' ).find( 'input, select' ); @@ -170,7 +190,7 @@ function gwDisableDuplicates( $elem, $group, selected ) { // Some elements have a parent element (e.g. a