-
-
Notifications
You must be signed in to change notification settings - Fork 3
Added support for checkboxes #45
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
Conversation
WalkthroughThis pull request introduces new properties to a model and updates the associated view to reflect these changes with additional checkbox inputs. A new TagHelper class is added to render checkbox controls with Bootstrap styling and improved model binding. In addition, the label generation method is extended to accept customizable parameters for enhanced HTML output. These changes facilitate better user input options and more flexible form rendering in the ASP.NET Core application. Changes
Sequence Diagram(s)sequenceDiagram
participant V as View
participant T as FormCheckboxTagHelper
participant G as IHtmlGenerator
participant E as FormElementMixinExtensions
V->>T: Request checkbox rendering for a model property
T->>G: Generate input element with type "checkbox"
alt Checkbox is disabled
T-->>T: Add "disabled" attribute and "form-check-input" class
else Normal checkbox
T-->>T: Add "form-check-input" class
end
T->>E: Call AddLabel(output, cssClass, isPostElement)
E-->>T: Append label to correct output section
T->>V: Return rendered checkbox HTML
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (3)
src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Models/SampleModel.cs (1)
43-44: Consider adding a description attribute for SetDefaultPassword.Add a
[Description]attribute to provide more context about what this setting does and its implications.[Display(Name = "Set Default Password")] +[Description("When enabled, a default password will be generated and set for the user.")] public bool SetDefaultPassword { get; set; }src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/StandardForm.cshtml (1)
33-39: Improve the checkbox group structure and styling.The checkbox group can be enhanced with better styling and more descriptive text.
<div class="mb-3"> - <label>Select Your Options</label> + <label class="form-label fw-bold">Preferences</label> + <p class="text-muted small mb-2">Please select your preferences below:</p> - <form-checkbox asp-for="Item1" container-class=""></form-checkbox> + <form-checkbox asp-for="Item1" container-class="ms-2"></form-checkbox> - <form-checkbox asp-for="Item2" container-class=""></form-checkbox> + <form-checkbox asp-for="Item2" container-class="ms-2"></form-checkbox> - <form-checkbox asp-for="Item3" container-class=""></form-checkbox> + <form-checkbox asp-for="Item3" container-class="ms-2"></form-checkbox> - <form-checkbox asp-for="Item4" container-class=""></form-checkbox> + <form-checkbox asp-for="Item4" container-class="ms-2"></form-checkbox> </div>src/AspNetCore.Utilities.Bootstrap5TagHelpers/Form/FormCheckboxTagHelper.cs (1)
67-72: Enhance switch accessibility and validation.When rendering as a switch, ensure proper ARIA attributes and validation.
-var groupClass = $"form-check {ContainerClass}"; +var groupClass = $"form-check {SafeContainerClass}"; if (IsSwitch) { groupClass += " form-switch"; + output.Attributes.SetAttribute("role", "switch"); - output.Attributes.Add("role", "switch"); + output.Attributes.SetAttribute("aria-checked", For.Model?.ToString()?.ToLower() ?? "false"); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Models/SampleModel.cs(1 hunks)src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/StandardForm.cshtml(1 hunks)src/AspNetCore.Utilities.Bootstrap5TagHelpers/Form/FormCheckboxTagHelper.cs(1 hunks)src/AspNetCore.Utilities.Bootstrap5TagHelpers/Form/FormElementMixin.cs(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build and Analyze
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (1)
src/AspNetCore.Utilities.Bootstrap5TagHelpers/Form/FormElementMixin.cs (1)
37-52: LGTM! Well-structured label generation with flexible placement.The changes to the AddLabel method are well-implemented, providing good flexibility for label placement and styling while maintaining clean code structure.
src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Models/SampleModel.cs
Show resolved
Hide resolved
| [Display(Name = "Agree to Terms (Disabled)")] | ||
| public bool AgreeToTerms { get; set; } = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add Required attribute for terms agreement.
Since this is a terms agreement checkbox, consider making it required and adding a description.
[Display(Name = "Agree to Terms (Disabled)")]
+[Required(ErrorMessage = "You must agree to the terms to continue.")]
+[Description("By checking this box, you agree to our terms and conditions.")]
public bool AgreeToTerms { get; set; } = true;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| [Display(Name = "Agree to Terms (Disabled)")] | |
| public bool AgreeToTerms { get; set; } = true; | |
| [Display(Name = "Agree to Terms (Disabled)")] | |
| [Required(ErrorMessage = "You must agree to the terms to continue.")] | |
| [Description("By checking this box, you agree to our terms and conditions.")] | |
| public bool AgreeToTerms { get; set; } = true; |
Summary by CodeRabbit