Created
December 22, 2025 12:28
-
-
Save Armenvardanyan95/98dea57683b9a2a59008b206e94fd30e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| imports: [Field], | |
| template: ` | |
| <form> | |
| <div> | |
| <label>Reason: </label> | |
| <select [field]="form.reason"> | |
| <option value="scheduling">Scheduling conflict</option> | |
| <option value="price">Price</option> | |
| <option value="other">Other</option> | |
| </select> | |
| </div> | |
| <div> | |
| <label>Explanation: </label> | |
| <textarea [field]="form.explanation" placeholder="Please explain..."></textarea> | |
| @if (form.explanation().touched() && form.explanation().invalid()) { | |
| <span style="color: red;"> * Required when 'Other' is selected</span> | |
| } | |
| </div> | |
| <button type="submit" [disabled]="form().invalid()">Submit</button> | |
| </form> | |
| `, | |
| }) | |
| export class CancellationComponent { | |
| cancellation = signal({ | |
| reason: '', | |
| explanation: '' | |
| }); | |
| form = form(this.cancellation, ctx => { | |
| required(ctx.reason); | |
| required(ctx.explanation, { | |
| when: () => this.cancellation().reason === 'other' | |
| }); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment