From a3bfe4269afc19dfd2e3a11e949455fdf6c7ad1d Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Mon, 13 Jul 2020 13:15:20 -0400 Subject: [PATCH 1/7] Also show state/moderation change. Makes no sense to have it around filling up space if save button is hidden too. --- js/hidenodeaction-webform_strawberryfield.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/hidenodeaction-webform_strawberryfield.js b/js/hidenodeaction-webform_strawberryfield.js index b26ec21..4b6ec65 100644 --- a/js/hidenodeaction-webform_strawberryfield.js +++ b/js/hidenodeaction-webform_strawberryfield.js @@ -26,6 +26,7 @@ Entity Form. */ $('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').show(); + $('.path-node .node-form div[data-drupal-selector="edit-footer"]').not('.webform-actions').show(); $('.webform-confirmation').closest('[data-strawberryfield-selector="strawberry-webform-widget"]').each(function() { var $id = $(this).attr('id') + '-strawberry-webform-close-modal'; $('#' + $id).toggleClass('js-hide'); @@ -34,6 +35,7 @@ } else if ($('div.field--widget-strawberryfield-webform-inline-widget').length) { $('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').hide(); + $('.path-node .node-form div[data-drupal-selector="edit-footer"]').not('.webform-actions').hide(); } var $moderationstate = $('select[data-drupal-selector="edit-moderation-state-0-state"]', context).once('show-hide-actions'); if ($moderationstate.length) { From 9f629c3dd052ee1e057e405b9844a3cf27f14ab8 Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Tue, 14 Jul 2020 09:13:35 -0400 Subject: [PATCH 2/7] Forcely attach the library when using the non inline webform --- src/Plugin/Field/FieldWidget/StrawberryFieldWebFormWidget.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Plugin/Field/FieldWidget/StrawberryFieldWebFormWidget.php b/src/Plugin/Field/FieldWidget/StrawberryFieldWebFormWidget.php index 9cb0c91..f24e5eb 100644 --- a/src/Plugin/Field/FieldWidget/StrawberryFieldWebFormWidget.php +++ b/src/Plugin/Field/FieldWidget/StrawberryFieldWebFormWidget.php @@ -324,7 +324,8 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#id' => 'webform_output_' . $this_widget_id, '#default_value' => $current_value['creation_method'], ]; - + // Because the actual form attaches via AJAX the library/form alter never triggers my friends. + $element['#attached']['library'][] = 'webform_strawberryfield/webform_strawberryfield.nodeactions.toggle'; return $element; } From e279337cf57eddbe33aa52694cb08171aaaea602 Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Tue, 14 Jul 2020 09:25:19 -0400 Subject: [PATCH 3/7] Cover also the non inline widget here --- js/hidenodeaction-webform_strawberryfield.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/hidenodeaction-webform_strawberryfield.js b/js/hidenodeaction-webform_strawberryfield.js index 4b6ec65..1599ac4 100644 --- a/js/hidenodeaction-webform_strawberryfield.js +++ b/js/hidenodeaction-webform_strawberryfield.js @@ -33,7 +33,11 @@ }) - } else if ($('div.field--widget-strawberryfield-webform-inline-widget').length) { + } else if ( + $('div.field--widget-strawberryfield-webform-inline-widget').length || + $('div.field--widget-strawberryfield-webform-widget').length + ) + { $('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').hide(); $('.path-node .node-form div[data-drupal-selector="edit-footer"]').not('.webform-actions').hide(); } From 2e6b54c180dd1fbfa551364bdeeb43c70e23094f Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Tue, 14 Jul 2020 09:36:36 -0400 Subject: [PATCH 4/7] Trying to be more precise about selectors here --- js/hidenodeaction-webform_strawberryfield.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/hidenodeaction-webform_strawberryfield.js b/js/hidenodeaction-webform_strawberryfield.js index 1599ac4..efe5bb7 100644 --- a/js/hidenodeaction-webform_strawberryfield.js +++ b/js/hidenodeaction-webform_strawberryfield.js @@ -34,8 +34,8 @@ } else if ( - $('div.field--widget-strawberryfield-webform-inline-widget').length || - $('div.field--widget-strawberryfield-webform-widget').length + $('div.field--widget-strawberryfield-webform-inline-widget form.webform-submission-form').length || + $('div.field--widget-strawberryfield-webform-widget form.webform-submission-form').length ) { $('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').hide(); From c99fbda8dc060f385a0831caa40f9779bb100bd6 Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Tue, 14 Jul 2020 11:36:04 -0400 Subject: [PATCH 5/7] Humble attempt at making nominatim better This is a response to a detail that bothers me: When you search for a place and then select, the option you selected sticks during the whole session. Let's say selection has 4 results and you select number 4, if you search again, the selected option is again number 4, independently that this is another place in earth. Things get serious when the response has only one! In that case you can no longer select anything because its already selected. I need to double check if i will have to also modify the user input here or not --- src/Element/WebformNominatim.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Element/WebformNominatim.php b/src/Element/WebformNominatim.php index 34769c9..2ebf3e5 100644 --- a/src/Element/WebformNominatim.php +++ b/src/Element/WebformNominatim.php @@ -317,6 +317,9 @@ public static function nominatimFetchSubmit( ); } } + // Reset current selection, if any. That way we can deselect wrongly made options + // By researching. + $form_state->set($my_geosjonkey.'-table-option', NULL); // Rebuild the form. $form_state->setRebuild(TRUE); } From 571c0b595997f94f009970560300dddca08e45de Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Tue, 14 Jul 2020 14:53:32 -0400 Subject: [PATCH 6/7] Well well well, this reset now works correctly. I knew i had to mangle with the user input. Damn table selects! --- src/Element/WebformNominatim.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Element/WebformNominatim.php b/src/Element/WebformNominatim.php index 2ebf3e5..659b13e 100644 --- a/src/Element/WebformNominatim.php +++ b/src/Element/WebformNominatim.php @@ -168,6 +168,7 @@ public static function processWebformComposite( 'category' => $feature->value->properties->category, ]; } + dpm($form_state->get($my_geosjonkey.'-table-option')); $element['feature']['table'] = [ '#title' => t('OpenStreet Map Nominatim Best Matches'), '#type' => 'tableselect', @@ -320,6 +321,11 @@ public static function nominatimFetchSubmit( // Reset current selection, if any. That way we can deselect wrongly made options // By researching. $form_state->set($my_geosjonkey.'-table-option', NULL); + $userinput = $form_state->getUserInput(); + // Only way to get that tableselect form to rebuild completely + unset($userinput[$top_element['#name']]['feature']['table']); + $form_state->setUserInput($userinput); + // Rebuild the form. $form_state->setRebuild(TRUE); } From d3aa69f568b127d790b9cb38bfc7be38afcc11ea Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Tue, 14 Jul 2020 14:55:34 -0400 Subject: [PATCH 7/7] And remove the debug output! --- src/Element/WebformNominatim.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Element/WebformNominatim.php b/src/Element/WebformNominatim.php index 659b13e..d769e0d 100644 --- a/src/Element/WebformNominatim.php +++ b/src/Element/WebformNominatim.php @@ -168,7 +168,6 @@ public static function processWebformComposite( 'category' => $feature->value->properties->category, ]; } - dpm($form_state->get($my_geosjonkey.'-table-option')); $element['feature']['table'] = [ '#title' => t('OpenStreet Map Nominatim Best Matches'), '#type' => 'tableselect',