silverstripe-asset-admin icon indicating copy to clipboard operation
silverstripe-asset-admin copied to clipboard

DropDownField read only transformation bug

Open mfendeksilverstripe opened this issue 6 years ago • 3 comments

Silverstripe Admin version: 1.2.1@stable (05276c9e63475ea3c7af57c8189abbc24e4cf088) "silverstripe/framework": "4.2.1@stable" (9d7eefce1dd19af1087e2ee8fe75e4cc07766d51)

I found this strange issue with DropDownField in Form which is used on the File select modal dialog in UploadField.

When user is selecting an image via upload field, he will get a read only version of the file details form as he is supposed to just choose the file, not edit it. We added a bunch of DropDownFields to that form and we are changing them to be read only in case the form is rendered from UploadField context.

There are two ways how to make DropDownFields read only.

Transformation 1:

$field->setReadonly(true);

Transformation 2:

$newField = $field->performReadonlyTransformation();

We have two types of DropDownField in the form:

Type 1:

Source data of these dropdown fields come from enum values, the source looks like this:

[
    'Value 1' => 'Value 1',
    'Value 2' => 'Value 2',
    'Value 3' => 'Value 3',
]

Type 2:

Source data of these dropdown fields come from datalists, the source looks like this:

[
    1 => 'Value 1',
    2 => 'Value 2',
    3 => 'Value 3',
]

Type 1 Dropdown fields are correctly displayed only when Transformation 1 is used. Type 2 Dropdown fields are correctly displayed only when Transformation 2 is used.

All other combinations will lead to incorrect value in the read only field.

Incorrect display means that the read only field will have 'none' value instead of the correct selected value from dropdown field.

This issue is present only in the context of asset admin. I would expect all fields to be displayed correctly with the same transformation.

mfendeksilverstripe avatar Aug 24 '18 01:08 mfendeksilverstripe

I've tried a variety of combinations of enum and DataList based sources on two DropdownFields, using both of the two readonly transformer examples above, and can't reproduce the issue.

I'm testing on SS 4.3.x-dev by modifying File and AssetFormFactory directly to add the form fields, and testing in the asset-admin file edit screen (when you click on a file in the Assets area).

Would you be able to provide more detail to help me reproduce this?

I did find this, as a side note: https://github.com/silverstripe/silverstripe-admin/issues/893

robbieaverill avatar Jun 13 '19 22:06 robbieaverill

@robbieaverill Thanks for the update. I tested this again and the issue is still present.

For example:

DropDownField with this data source:

[
    1 => 'Value 1',
    2 => 'Value 2',
    3 => 'Value 3',
]

Let's assume value 1 is selected.

If $field->setReadonly(true); is used the read only field will yeild 1 If $field->performReadonlyTransformation(); is used the read only field will yeild Value 1'

mfendeksilverstripe avatar Jun 18 '19 23:06 mfendeksilverstripe

Thanks!

robbieaverill avatar Jun 18 '19 23:06 robbieaverill