Skip to content

Commit b386af1

Browse files
authored
Merge pull request #102 from systopia/prevent-initial-recalculation-on-file-fields
Prevent initial calculation on file fields
2 parents cff26a7 + 46ba1a5 commit b386af1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Form/Control/Util/BasicFormPropertiesFactory.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ public static function createFieldProperties(ControlDefinition $definition, Form
9090
if ($definition->isCalculated()) {
9191
$formState->set('$calculateUsed', TRUE);
9292
}
93-
elseif (TRUE !== $formState->get('$hasCalcInitField') && 'hidden' !== $definition->getOptionsValue('type')) {
93+
elseif (TRUE !== $formState->get('$hasCalcInitField')
94+
// Change event cannot be triggered on hidden fields.
95+
&& 'hidden' !== $definition->getOptionsValue('type')
96+
// A field of type managed_field might be used which is rendered in a way
97+
// that it cannot be used as field for initial calculation.
98+
&& 'file' !== $definition->getControlFormat()
99+
) {
94100
$formState->set('$hasCalcInitField', TRUE);
95101
$calcInitField = TRUE;
96102
}
@@ -126,7 +132,7 @@ public static function createFieldProperties(ControlDefinition $definition, Form
126132

127133
if ((!$form['#disabled'] && TRUE === $formState->get('recalculateOnChange')) || $calcInitField) {
128134
$form['#ajax'] = [
129-
'callback' => RecalculateCallback::class . '::onChange',
135+
'callback' => [RecalculateCallback::class, 'onChange'],
130136
'event' => 'change',
131137
'progress' => [],
132138
'disable-refocus' => TRUE,

0 commit comments

Comments
 (0)