Conditional “X-Prompt” in Angular Schematics
See original GitHub issueIt seems feature to add conditional x-prompts is missing in angular schematics.
Requirement : To display conditional prompts, based on the previous selection ( “Analytics”, in this case ).
Problem : For any selection, it is still displaying the prompt to add Google Analytics’s Tracking Id even if i select AppDynamics or none.
References : Applying Subschemas Conditionally Angular Schematics
Note: For Simplicity, i have removed “allOf”,“anyOf” etc. and code for any other analytics tool, still it was not working.
Code (Schema.json):
{
"$schema": "http://json-schema.org/schema",
"id": "MyDemoSchema",
"title": "My Demo Schematics Schema",
"type": "object",
"properties": {
"analytics": {
"enum": [
"none",
"GoogleAnalytics",
"AppDynamics"
],
"x-prompt": "Which Analytics would you like to use?"
}
},
"if": {
"properties": {
"analytics": {
"const": "GoogleAnalytics"
}
}
},
"then": {
"properties": {
"GoogleAnalytics": {
"type": "string",
"x-prompt": "Enter Tracking ID?"
}
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:37
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Angular schematics conditional property/prompt - Stack Overflow
What I've discovered - if you need conditional prompts, then you can't ... import { askConfirmation } from '@angular/cli/utilities/prompt'; ...
Read more >Enhance developer experience: Use prompts in your schematics
Okay so first step to adding prompts to our schematics is to add x-prompt to your schema.json . Now if you aren't familiar...
Read more >Angular CLI Prompts | Blog - Kevin Schuchard
In order to prompt the user for a selection, you can both provide suggestions and limit the possible choices with the enum type....
Read more >Authoring schematics - Angular
Similarly, you can add a prompt to let the user decide whether the schematic uses color when executing its hello action. The schema...
Read more >The Complete Guide to Custom Angular Schematics - Morioh
Prompts are the way to provide schematic options without the need to know about them before hand. To use them we have to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have the same goal but a different proposal. Instead of increasing the basic schema.json feature-set, I’d rather use a second function-driven API. I believe adding a condition API to a json file will increase the complexity tremendously.
Here’s a proposal. It certainly contains lots of flaws and is meant as a start to discuss further possible approaches.
collection.json
dynamic/schema.ts#conditionalInputs
Angular framework (pseudo code)
Having an interface in the user code is intentional. Right now, if I am writing a schematic, the input properties are not typed and I need to manage two lists of inputs in parallel (schema.json inputs / schematic factory code input type)
Any thoughts on this? Or maybe disagreement to a TS API? 🙂
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.