Solved: How to fill a SingleSelectDropdown with a fusion array

Hi everybody,

I’m rendering a form with

<form:render persistenceIdentifier="modul-registration-form"
  overrideConfiguration="{renderables:{0:{renderables:{0:{properties:{options:myDates}}}}}}"/>

myDates is built from a node property of type text that has multiple lines where each line has a date. In my fusion I’ve got the following line:

myDates = ${String.pregSplit(daysAvailable, '/\n/')}

So I get the following array, which is perfect overridden in my form:

myDates = {
  0 => dateAvailable1, 
  1 => dateAvailable2, 
  2 => dateAvailable3
}

This works fine so far. But I’m stuck here.
The first problem I have to solve, is that my array should look like this:

myDates = {
  dateAvailable1 => dateAvailable1,
  dateAvailable2 => dateAvailable2,
  dateAvailable3 => dateAvailable3
}

I was trying to solve this with:

myDates = ${Array.map(String.pregSplit(daysAvailable, '/\n/'), x => {x=>x})}

and:

myDates = ${Array.map(String.pregSplit(daysAvailable, '/\n/'), x => x)}

Both versions don’t help.

The 2nd problem: I have another field with daysBooked which has the same format as daysAvailable. The result should be an option list that is sorted where daysBooked should get the attribute disabled in the final dropdown.

Is it possible to solve this problem in fusion or do I have to go a different way?

After viewing codes and documentation, I couldn’t find a possibility to add opions to SingleSelectDropdown that carry the disabled attribute. :cry:

Therefore, I changed the code to load the options with JavaScript when form gets displayed.

sorry for no response but for the record:

Array.map only cares about the returned values of the arrow function closure, you cant change the keys. ArrayHelper.php

so next time you could create a new Eel helper (see docs - Custom Eel Helpers), which will allow to return a changed key and value.

its name could be My.Object.map (eel objects are normal php associative arrays key => value)

root = Neos.Fusion:Value {
    thing = ${ ['foo', 'bar'] }
    value = ${ My.Object.map(this.thing, (key, value) => [value, value] }
}

this would return:

[
    'foo' => 'foo',
    'bar' => 'bar'
]

eel helper method:

public function map(array $array, callable $callback): array
{
    $result = [];
    foreach ($array as $key => $value) {
        list($newKey, $newValue) = $callback($key, $value);
        $result[$newKey] = $newValue;
    }
    return $result;
}

of course you could also just create highly specific eel helpers for your usecase …

Thx for your reply. I’ll give it a try.