WCF icon indicating copy to clipboard operation
WCF copied to clipboard

Make MultipleSelectionFormField nullable again

Open IceQ1337 opened this issue 3 years ago • 0 comments

Reference: https://github.com/WoltLab/docs.woltlab.com/issues/302

The change definitely made sense, is reasonable and provides a good way to further process the multiple selection data with its own subarray. But, in my opinion, the MultipleSelectionFormField should still have an option to pass 'null' to the 'data' subarray directly in the case of an empty selection. This saves the developer from manually setting the save value to 'null' for every form field of this type in the ObjectAction::create() and the ObjectAction::update() function (or elsewhere). Currently, for example, an empty selection does not update the save value at all, but I can imagine that this is exactly the result that is often desired, because if there was a selection before, it has now been deliberately removed.

Of course, since arrays cannot be stored as is, the developer must decide how to handle (further process) the data and how to save it, but it shouldn't be necessary to explicitly set it to 'null' every time if the form field can just have its own implementation of nullable().

if (isset($this->parameters['selection']) && \is_array($this->parameters['selection'])) {
    $this->parameters['data']['selection'] = \serialize($this->parameters['selection']);
} else {
    $this->parameters['data']['selection'] = null;
}

Maybe I'm missing something, but I'd say that using many fields of this type in a single form quickly bloats the validation unnecessarily.

IceQ1337 avatar Sep 25 '22 12:09 IceQ1337