atk4 / ui

Robust and easy to use PHP Framework for Web Apps
https://atk4-ui.readthedocs.io
MIT License
440 stars 104 forks source link

DropdownCascade does not have multiple values support #2125

Open mkrecek234 opened 8 months ago

mkrecek234 commented 8 months ago

DropdownCascade disables multiplesupport. This can be easily activated if we change the DropdownCascade's getJsValues function to:

/**
     * Will mark current value as selected from a list
     * of possible values.
     *
     * @param string|int $value the current field value
     */
    private function getJsValues(array $values, $value): array
    {
        foreach ($values as $k => $v) {
            if (!$this->multiple) {
                if ($v['value'] === $value) {
                    $values[$k]['selected'] = true;

                    break;

                }
            } else {
                if (in_array($v['value'], explode(',', $value))) {
                    $values[$k]['selected'] = true;
                }

            }
        }

        return $values;
    }

Plus we have to remove line https://github.com/atk4/ui/blob/6b503a72e051ca0aea0ddf0a18aecf77bf3b9adf/src/Form/Control/DropdownCascade.php#L117

Happy to submit via PR, but unfortunately can only provide a demo example, but no behat test.

mvorisek commented 8 months ago

should be solved as part of https://github.com/atk4/ui/issues/1020

mvorisek commented 3 months ago

PR welcomed.