Plugin Math: just integer values are accepted

Created on 2 February 2024, 5 months ago
Updated 19 April 2024, 2 months ago

Problem/Motivation

I'm looking for a solution to do simple math operations and ECA Tamper Integration:Math fits. But just integer values are accepted as value, description says 'a numerical value'. I.e. value '9.99' throws an error 'value is not a valid number'. Value '10.00' works.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

1.0

Component

User interface

Created by

🇩🇪Germany fsiemens

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @fsiemens
  • Status changed to Postponed: needs info 5 months ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    I can't reproduce this unfortunately. ECA Tamper doesn't verify the data type as far as I can tell. And the only data type validation can be found in the tamper module, which does something like this:

        if (!is_numeric($data)) {
          throw new TamperException('Math plugin failed because data was not numeric.');
        }
    

    So, can you please provide an example to reproduce the problem, and also let us know the exact error message and when it is being displayed.

  • 🇩🇪Germany fsiemens

    Clean Installation Drupal Core 10.2
    Installed moduls Tamper 8.x-1.0-alpha4; ECA: Event - Condition - Action 1.1.4; ECA Tamper Integration 1.0.5; BPMN.iO 1.1.3

    Simple model with math operation addition.
    The error is displayed when saving the model with a non-integer numerical value i.e. '5.99'.

    Two Error messages:
    Model contains error(s) and can not be saved.
    action "Manipulation: Math" (): Value must be a number.

  • Status changed to Active 4 months ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Ah, this is a field value validation on number fields. Here is what the tamper module uses for their math plugin:

        $form[self::SETTING_VALUE] = [
          '#type' => 'number',
          '#title' => $this->t('Value'),
          '#required' => TRUE,
          '#description' => $this->t('A numerical value.'),
          '#default_value' => $this->getSetting(self::SETTING_VALUE),
        ];
    

    This generates a HTML number field, and they define number as integer. On submission, Drupal core is validating number field such that they have to be integers.

    Not sure if the tamper module wants to change that field type, moving it over there for review.

  • Assigned to MegaChriz
  • 🇳🇱Netherlands MegaChriz

    Yes, this should be fixed in the Tamper module indeed. The Math plugin should be able to accept decimal values. It looks like that it can be fixed by setting the 'step' attribute to 'any'. I found that answer here: https://stackoverflow.com/questions/34057595/allow-2-decimal-places-in-i...

    I'm working on a fix.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 4 months ago
    534 pass
  • Issue was unassigned.
  • Status changed to Needs review 4 months ago
  • 🇳🇱Netherlands MegaChriz

    A fix is ready for review. Let me know if this fixes the issue for you. :)

  • 🇧🇪Belgium herrzhull

    Was looking for the same - tested it on a dev site and this seems to solve the issue. It would be awesome if this could be bumped to dev so I don't need to apply a patch just for one line :).

  • Pipeline finished with Skipped
    3 months ago
    #138573
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 3 months ago
    534 pass
  • Status changed to Fixed 3 months ago
  • 🇳🇱Netherlands MegaChriz

    Thanks for testing @TTNT! I merged the code.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024