Skip to content

Ui\Dropdown with typecasting bug #2236

@mkrecek234

Description

@mkrecek234

Steps to reproduce:

  • Add a Ui\Dropdown view and setModel for any model with a usual bigint idField
  • Configure Dropdown->onChange to handle selected item
  • Select an entry of the dropdown

Sample code:

    $agentdropdown = \Atk4\Ui\Dropdown::addTo($app, ['Select agent', 'dropdownOptions' => ['on' => 'hover']]);
    $agentdropdown->setModel($agentmodel);

    $agentdropdown->onChange(static function ($itemId) {
        return "do something with ".$itemId;
    });

Typecasting error TypeError: Atk4\Ui\Dropdown::Atk4\Ui\{closure}(): Argument #2 ($value) must be of type string, int given, called in vendor/atk4/ui/src/JsCallback.php on line 90

Solution:

$this->cb->set(static function (Jquery $j, string $value) use ($fx) {

The itemId here is forced to be string, however the idField is typecasted as int. This has to be adapted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions