getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.32k stars 169 forks source link

Radio field in custom dialog: issues with options #4902

Closed adamkiss closed 1 year ago

adamkiss commented 1 year ago

Description

When using radio field in a custom dialog, options in value: text format[1] are not loaded. If these options are expanded to the format defining "value" and "text" separately[2], default option is ignored if the field's value in the value props isn't defined.

[1] simple format:

default: opt1
options:
  opt1: Option 1

[2] alternative format:

default: opt1
options:
  - text: Option 1
    value: opt1

Expected behavior

  1. Options are correctly loaded for the simple format
  2. If the dialog.props.value.[field-name] isn't defined, default value is correctly selected

Screenshots

CleanShot 2022-12-07 at 20 21 34@2x

To reproduce

  1. Create a simple plugin to create a custom dialog (example replacing site:page.changeStatus)
  2. Try to change status
  3. Observe bugs

Your setup

Kirby Version
3.8.3

distantnative commented 1 year ago

Not sure I get your examples. I assume you just write them here in a blueprint notation, because actually you should be passing a PHP array. And for that, yes there likely will differences to the blueprint notations. But I wouldn't consider these a bug but expected behaviour.

adamkiss commented 1 year ago

@distantnative yes, i just showed the setup as yaml for brevity, otherwise the definition is a PHP array.

distantnative commented 1 year ago

Ok, I hope I can explain this in a way that makes sense:

If you pass fields etc to Fiber dialogs, the values you pass are directly the props that the Vue components will receive. Which is different to blueprints that first undergo transformation, logic etc. (most located in config/fields).

To achieve the same, you would probably first need to create a return new Form(['fields' => ..., 'values' => $..., 'model' => ...]);. And from that form get the values to pass as raw props to your dialog fields.

adamkiss commented 1 year ago

That's fair, and looking at <k-select-input>'s code, I can see that it expects Array for options, which key: value pair in Javascript isn't.

Anyway, if this is expected, I'm closing this.

distantnative commented 1 year ago

One day I hope we might offer something easier like (new Blueprint(...))->fields()->props()