The "required" tamper does not work with false, zero etc. values

Created on 13 March 2024, about 1 year ago
Updated 11 April 2024, 12 months ago

Problem/Motivation

The required tamper uses the empty function to decide if it exists or not. This doesn't work well with zero and false values.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇷🇴Romania bbu23

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

Comments & Activities

  • Issue created by @bbu23
  • 🇳🇱Netherlands megachriz

    Alright, maybe we need two settings then:

    • Count the number 0 as empty
    • Count the boolean false as empty

    The first text is taken from Views, where that is used to determine wether or not there is a result. We might even copy the method Drupal\views\Plugin\views\field\FieldPluginBase::isValueEmpty() to the Required plugin.

    And I think we need to have these settings enabled by default, for backwards compatibility.

  • 🇷🇴Romania bbu23

    I see. But you mean "have these settings" disabled by default, right? I mean, if you want to have backwards compatibility, they are supposed to be disabled, since currently they act as if they were off.

  • 🇳🇱Netherlands megachriz

    No, the current behavior is as follows:

    • The number 0 is considered to represent an empty value.
    • The boolean false is considered to represent an empty value.

    So if the passed value is 0 or false, the item will not be processed currently.

    So if you want the item to be processed on 0 or false (but not on null), the proposed settings "Count the number 0 as empty" and "Count the boolean false as empty" should be disabled. And to preserve the current behaviour, these settings should therefore be enabled by default.

  • 🇷🇴Romania bbu23

    Ah, yes, you're right haha I got confused in my own initial report :D

Production build 0.71.5 2024