Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend component property type of Set does not work #5530

Closed
maraerben opened this issue Mar 8, 2021 · 2 comments
Closed

Backend component property type of Set does not work #5530

maraerben opened this issue Mar 8, 2021 · 2 comments

Comments

@maraerben
Copy link
Contributor

maraerben commented Mar 8, 2021

  • OctoberCMS Build: 471
  • PHP Version: 7.2
  • Database Engine: PostgreSQL 11.3
  • Plugins Installed: RainLab.Pages

Description:

I develop my own plugin with custom Component. This component has property type of Set. This property has defined some options and default value too.

Default value is visible in backend are correctly, see first screenshot. (In CMS editor)

Snímek obrazovky 2021-03-08 v 10 47 05

When I want to select another (non-default) options, none is actually selected. See second screenshot.

Snímek obrazovky 2021-03-08 v 10 49 07

Steps To Reproduce:

<?php

use Cms\Classes\ComponentBase;

class ProductsList extends ComponentBase {

  public function defineProperties(): array
  {
    return [
      'productTypeExternalIds' ⇒ [
        'title' => 'Product types,
        'type' => 'set', # problem with set, e.g. dropdown works file, but I need multiple items selected
        'default' => [123],
        'required' => true
      ]
    ];
  }

  public function getProductTypeExternalIdsOptions(): array
  {
    return [
      123 => 'Some product',
      200 => 'Another product',
    ];
  }
}
@maraerben
Copy link
Contributor Author

Hmm ... It looks like it works when keys of options array are strings. E.g. option-123, option-200, ... It is necessary to parse the integer from key later.

@daftspunk
Copy link
Member

Confirmed the same thing, the key values must be strings and then you can cast them to integers later, if necessary. Made a note to get this fixed in a later release. Thanks @maraerben !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants