silverstripe / silverstripe-admin

Silverstripe Admin Component
BSD 3-Clause "New" or "Revised" License
25 stars 92 forks source link

Lazyloaded SearchableDropdownField does not work in elemental #1778

Closed emteknetnz closed 3 months ago

emteknetnz commented 3 months ago

Lazyloaded SearchableDropdownField does not function correctly when using in elemental. Selecting a value does not visually update the field, though when you save the value is saved. I tested using an autoscaffolded field, meaning I had over 100 DataObject which I create via requireDefaultFields(). When setting ->setIsClearable(true) on DBForeignKey.php, when I clicked the clear button I got console warnings (I had run yarn dev in admin)

Discovered when implementing https://github.com/silverstripe/silverstripe-framework/pull/11273

Note this isn't an issue when using a SearchableDropdownField in a regular form

Test setup:

You'll need dnadesign/silverstripe-elemental installed

MyBlock.php

<?php

use DNADesign\Elemental\Models\BaseElement;

class MyBlock extends BaseElement
{
    private static $db = [
        'MyField' => 'Varchar',
    ];

    private static $has_one = [
        'MySubDataObject' => MySubDataObject::class,
    ];
    private static $table_name = 'MyBlock';

    private static $singular_name = 'My Block';

    private static $plural_name = 'My Blocks';

    private static $description = 'This is my block';

    private static $icon = 'font-icon-block-content';

    public function getType()
    {
        return 'My Block';
    }
}

MySubDataObject.php

<?php

use SilverStripe\ORM\DataObject;

class MySubDataObject extends DataObject
{
    private static $table_name = 'MySubDataObject';

    private static $db = [
        'Title' => 'Varchar'
    ];

    private static $has_many = [
        'MyBlock' => MyBlock::class,
    ];

    public function requireDefaultRecords()
    {
        parent::requireDefaultRecords();
        if (self::get()->count() < 110) {
            for ($i = 0; $i < 110; $i++) {
                $record = self::create();
                $record->Title = 'MySubDataObject ' . $i;
                $record->write();
            }
        }
    }
}

New issues created

Shared CI run

PRs

GuySartorelli commented 3 months ago

PRs merged