diff --git a/src/Form/Control/Callbacks/RecalculateCallback.php b/src/Form/Control/Callbacks/RecalculateCallback.php index a5fb56d..421c996 100644 --- a/src/Form/Control/Callbacks/RecalculateCallback.php +++ b/src/Form/Control/Callbacks/RecalculateCallback.php @@ -39,6 +39,21 @@ public static function addAjaxCommands(AjaxResponse $response, FormStateInterfac RecalculateCallbackUtil::addAjaxCommands($response, $formState, $oldData, $newData); } + /** + * @param array $element + * + * @return array + */ + public static function processElement(array $element, FormStateInterface $formState): array { + if (TRUE !== $formState->get('$calculateUsed')) { + if (is_array($element['#ajax'] ?? NULL) && [static::class, 'onChange'] === $element['#ajax']['callback']) { + unset($element['#ajax']); + } + } + + return $element; + } + /** * @phpstan-param array $form $form */ diff --git a/src/Form/Control/Util/BasicFormPropertiesFactory.php b/src/Form/Control/Util/BasicFormPropertiesFactory.php index b81dc5c..e7d6fc5 100644 --- a/src/Form/Control/Util/BasicFormPropertiesFactory.php +++ b/src/Form/Control/Util/BasicFormPropertiesFactory.php @@ -138,6 +138,9 @@ public static function createFieldProperties(ControlDefinition $definition, Form 'progress' => [], 'disable-refocus' => TRUE, ]; + $form['#process'] = [ + [RecalculateCallback::class, 'processElement'], + ]; } $form += static::createBasicProperties($definition);