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

Feature request: dynamic messages and default values #174

Open
izeau opened this issue Jun 12, 2024 · 2 comments
Open

Feature request: dynamic messages and default values #174

izeau opened this issue Jun 12, 2024 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@izeau
Copy link
Contributor

izeau commented Jun 12, 2024

Description:

It'd be awesome if we could use answers from previous questions in our question messages and default values.

Current Limitations:

Right now, all our prompts and defaults are static and can't adapt based on previous answers.

Proposed Changes:

  1. Dynamic Messages:
    Let us use answers from earlier questions in new question prompts.

    questions:
      - name: player_name
        required: true
        prompt:
          message: What's your name?
    
      - name: player_age
        required: true
        prompt:
          message: And how old are you, {{ .Scaffold.player_name }}?
  2. Dynamic Default Values:
    Use previous answers to set default values with interpolations.

    questions:
      - name: player_name
        required: true
        prompt:
          message: What's your name?
    
      - name: player_alias
        required: true
        prompt:
          message: Now, pick an alias
          default: |-
            {{ regexReplaceAll "[^a-z]+" (.Scaffold.player_name | lower) "_" }}

Benefits:

  • Better Experience: More personalized and relevant questions.
  • Fewer Mistakes: Auto-suggested values cut down on errors.
  • More Flexible: Makes the questionnaire more adaptable.

What do you think?

@hay-kot
Copy link
Owner

hay-kot commented Jun 15, 2024

I like it! Fully support adding this, few things I can offer on the implementation:

  1. I don't know if this would be possible. I'm doing some pretty nargly things to get templating to work for the when field and I don't see a clear way to add support for this. It may require upstream changes in the huh library. - Which is to say, this will probably be more difficult that it initially seems.
  2. Important that we support all types of default values, list of strings is the only other one I can think of.
  3. For the templates for the when field, properties from preview inputs are available at top level ({{ .player_name}} vs {{ .Scaffold.player_name }}) I think this makes sense because none of the other top level properties are available.

Happy to work together to get this done, but my summer is pretty packed so may be gaps between when I can reply!

@izeau
Copy link
Contributor Author

izeau commented Jun 21, 2024

Hello! It looks like dynamic forms are on the roadmap for huh, but are not available yet. In the meantime they recommend using separate forms, but that kind of breaks the workflow I guess? I think we should wait until this is released :)

Enjoy your summer!

@hay-kot hay-kot added enhancement New feature or request help wanted Extra attention is needed labels Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants