setReadonly inconsistent

foreach ($fields->dataFieldNames() as $name)
{
    $fields->dataFieldByName($name)->setReadonly(true);
}

or

foreach (parent::getCMSFields() as $field)
{
    $field->setReadonly(true);
}

or

$fields->makeReadonly();

Those work on “normal” fields but it doesn’t work on things like:

  1. an Enum field that gets created into a select (chosen)
  2. has_one field
  3. Checkbox field
  4. MultiEnum that gets set to a Checkboxset field

For those types I have to manually replace the field with:

$status = $fields->dataFieldByName('Status')->performReadonlyTransformation();
$fields->replaceField('Status', $status);

The docs kind of allude to it:

readonly mode converts the input, select and textarea

Maybe it’s just a docs issue but would be nice if the form fields had consistent behaviour.

There is no such thing in the core modules of Silverstripe CMS as a "has_one field" or an “enum fied”. So I’m not sure which form fields you’re specifically saying this functionality doesn’t work for. It’s also not clear what you mean when you say “doesn’t work”.

But in any case, the forums is not the correct place to report bugs or inconsistencies in documentation. Can you please create an issue in one of the following github repositories?

@GuySartorelli meaning when those database fields or relations (eg has_one) have their form fields automatically created into either a select/chosen or a checkboxset.

“Doesn’t work” = the fields are not readonly…

I’m not reporting anything. I’m asking. This may well be expected behaviour.

I would say if the method is called setReadonly() and you set it to true, and it isn’t read only then that’s a clear bug.