apostrophe-cms

How to properly limit the quantity of pieces for a singleton


I've never been able to properly limit the quantity of pieces an editor can select when editing in context. This needs to be a singleton, as I understand, because an area offers many widgets.

In this case, there is only one type, and it can also be deleted, in case the editor does not want that placeholder filled.

However, when the editor wants to add a piece, what is the appropriate way to set that limit in code? All the options I pass are completely ignored, and the documentation does not show a code example, only properties that can be used.

{{
  apos.singleton(
    container,
    'propName',
    'module-name',
    {
      limitByAll: 1,
      limitByTag: 1,
      limitById: 1,
      limit: 1
    }
  )
}}

None of the options limit anything for the editor:

enter image description here

So I wonder, what is the proper way to enforce a limit for a singleton?


Solution

  • The pieces widgets module does not include a maximum number of pieces allowed when individually selecting them.

    This mode uses the joinByArray field. The joinByArray field does have an option, limit where you can specify the maximum number of joined pieces. But the pieces widget does not include that option.

    If you know this will always be used to individually choose pieces (and not use the tag or "all" modes) then you might want to create a new widget for your needs. When using the "Individually" mode, the pieces widget isn't very fancy. It's simply a widget with a joinByArray field.