-
-
Notifications
You must be signed in to change notification settings - Fork 235
Description
Actual Situation
I would like to create a Copier template for a React application in which the user can select any number of ready-made components from a single multiselect question. Before displaying that selection, I also want to ask whether they prefer to use a preset (e.g. ecommerce, trading, blog). If a preset is chosen, some components should be automatically selected and the template should generate the pages and configuration relevant to that preset.
Example components:
Cart(required forecommercepreset)BarChart(required fortradingpreset)HeroSection, (required forblogpreset)Carousel- etc.
Each preset relies on some of these components to render correctly. If the user removes those components, the generated preset pages would break (missing imports, routes, or sections).
What I’d like:
- A single
multiselectquestion with all available components. - Some components can be toggled freely.
- Some components are required and must stay selected when a given preset is chosen, because the preset pages depend on them.
- Required components cannot be unchecked in the interactive prompt.
Currently, as far as I understand:
- The
validatorfor choices is used to enable or disable a choice. - When a choice is disabled, it is also unchecked.
That means I can’t use the validator to express “this choice is required and must remain selected”:
- If I disable it, it gets unchecked.
- If I leave it enabled, the user can still uncheck it.
Desired Situation
The ability to conditionally pre-select choices in a multiselect and prevent the user from unchecking them.
Proposed solution
I think the simplest way to implement this, without introducing any new properties in the configuration, would be to conditionally set the default property based on the selected preset using Jinja, and then disable the choice using the validator property. For this to work, the validator should only disable the choice and a disabled choice should not be automatically unchecked.
Minimal example with a ecommerce preset with a required Cart component:
preset:
type: str
choices: [ecommerce, none]
default: none
components:
type: yaml
multiselect: true
choices:
Cart:
value: cart
validator: "{% if preset == 'ecommerce' %}Required by the preset{% endif %}"
default: |
{%- if preset == 'ecommerce' %}
- cart
{%- endif %}However, at the moment, setting a choice as default and then disabling it with a validator results in an error.