- 
                Notifications
    
You must be signed in to change notification settings  - Fork 9
 
Adjusted form #73
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
Adjusted form #73
Conversation
          
WalkthroughThe changes introduce enhanced validation feedback to a multi-step salary form. The HTML template now displays a validation summary alert in steps one and three, listing invalid fields grouped by page, using a new  Changes
 Sequence Diagram(s)sequenceDiagram
    participant User
    participant AddSalaryComponent
    participant EditSalaryForm
    User->>AddSalaryComponent: Interacts with salary form (multi-step)
    AddSalaryComponent->>EditSalaryForm: Submit or validate form
    EditSalaryForm->>EditSalaryForm: Check validity, collect invalid fields
    EditSalaryForm->>AddSalaryComponent: getInvalidFields() returns grouped invalid fields
    AddSalaryComponent->>User: Display validation summary alert with invalid fields by page
    Poem
 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
 ✅ Files skipped from review due to trivial changes (1)
 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 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 (
 | 
    
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: 1
🧹 Nitpick comments (3)
src/app/modules/salaries/components/add-salary/edit-salary-form.ts (3)
223-249: Consider making page count more dynamic.The method correctly groups invalid fields by page, but it hardcodes exactly three pages. This might cause issues if the form structure changes in the future.
Consider making the page count dynamic:
- const groupedByPage: InvalidFieldsGroupedByPage[] = [ - { - page: 1, - fields: [], - }, - { - page: 2, - fields: [], - }, - { - page: 3, - fields: [], - }, - ]; + // Get the maximum page number + const maxPage = Math.max(...this._invalidFields.map(field => field.page)); + + // Create an array of pages from 1 to maxPage + const groupedByPage: InvalidFieldsGroupedByPage[] = Array.from( + { length: maxPage }, + (_, i) => ({ + page: i + 1, + fields: [], + }) + );
251-251: Fix typo in method name.There's a typo in the method name - it should be "Label" not "Lable".
- private getControlNameLable(name: string): string { + private getControlNameLabel(name: string): string {Don't forget to update the reference to this method in
createAddRequestOrNull()as well.
279-300: Consider adding a comment about the default case.The method correctly assigns controls to form pages, but the default return of 0 might be confusing. Consider adding a comment explaining this case.
default: + // Return 0 for unknown fields as a fallback return 0;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/app/modules/salaries/components/add-salary/add-salary.component.html(2 hunks)src/app/modules/salaries/components/add-salary/edit-salary-form.ts(3 hunks)
🔇 Additional comments (5)
src/app/modules/salaries/components/add-salary/edit-salary-form.ts (3)
14-23: Well-structured interfaces for invalid fields tracking.The interfaces provide clear typing for tracking invalid fields in the multi-step form.
InvalidFieldsGroupedByPageallows grouping invalid fields by page, which is useful for providing feedback at different stages of the form completion.
28-28: Good initialization of the invalid fields tracking array.The private property is correctly initialized as an empty array to store invalid fields when form validation fails.
160-171: Good implementation of invalid fields tracking logic.This code correctly collects information about invalid form controls, including their page, control name, and user-friendly label when form validation fails.
src/app/modules/salaries/components/add-salary/add-salary.component.html (2)
5-5: Improved responsive padding.The change from "card-body form-container" to "card-body p-lg-5 p-3" provides better responsive padding (larger on desktop, smaller on mobile), improving UI consistency.
292-313: Well-implemented validation summary alert.This validation summary block is a good addition that:
- Only displays when there are invalid fields
 - Clearly shows which fields need attention, grouped by page
 - Uses nested numbering for better organization
 This will greatly improve user experience by providing clear feedback about validation issues across the multi-step form.
| <div class="mb-3" *ngIf="addSalaryForm.getInvalidFields().length > 0"> | ||
| <div class="alert alert-warning"> | ||
| <div class="mb-2"> | ||
| <strong>Внимание!</strong> Следующие поля не заполнены: | ||
| </div> | ||
| <div | ||
| class="mb-2" | ||
| *ngFor=" | ||
| let field of addSalaryForm.getInvalidFields(); | ||
| let i = index | ||
| " | ||
| > | ||
| <div>{{ i + 1 }}. Страница {{ field.page }}</div> | ||
| <div | ||
| class="ms-3" | ||
| *ngFor="let control of field.fields; let j = index" | ||
| > | ||
| {{ i + 1 }}.{{ j + 1 }}. {{ control }} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | 
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.
Missing validation summary for the first step.
The validation summary alert is only implemented for the third step of the form. According to the AI summary, it should be present on both the first and third steps to provide consistent feedback.
Add the same validation summary block to the first step of the form (around line 145, before the "Далее" button):
+          <div class="mb-3" *ngIf="addSalaryForm.getInvalidFields().length > 0">
+            <div class="alert alert-warning">
+              <div class="mb-2">
+                <strong>Внимание!</strong> Следующие поля не заполнены:
+              </div>
+              <div
+                class="mb-2"
+                *ngFor="
+                  let field of addSalaryForm.getInvalidFields();
+                  let i = index
+                "
+              >
+                <div>{{ i + 1 }}. Страница {{ field.page }}</div>
+                <div
+                  class="ms-3"
+                  *ngFor="let control of field.fields; let j = index"
+                >
+                  {{ i + 1 }}.{{ j + 1 }}. {{ control }}
+                </div>
+              </div>
+            </div>
+          </div>
+
           <div class="row mt-5">
             <div class="col-6"></div>
             <div class="col-6">
Summary by CodeRabbit