Files
psp_panel/src/app/uikit/uikit-field.component.ts
T
ahasani 50bc9a4632 feat(purchases): implement purchase receipt functionality with form and receipt template
- Added `ProductPurchaseComponent` to handle product purchases.
- Created `PurchaseReceiptTemplateComponent` for displaying purchase receipt details.
- Developed `PurchaseFormComponent` for managing purchase form inputs and submission.
- Introduced `ProductChargeRowFormComponent` and `ProductChargeRowFormFieldsComponent` for handling product charge rows in the form.
- Implemented `PurchaseReceiptProductRowComponent` for displaying individual product rows in the receipt.
- Established API routes for purchase operations in `apiRoutes`.
- Integrated suppliers and inventories selection components.
- Added utility functions for converting prices to Persian alphabet.
- Created a utility for generating full names from name parts.
- Enhanced form validation and submission handling in the purchase form.
- Updated styles and templates for improved UI/UX.
2025-12-09 20:17:00 +03:30

40 lines
1.3 KiB
TypeScript

import { FormErrorsService } from '@/core/services/form-errors.service';
import { CommonModule } from '@angular/common';
import { Component, Input, inject } from '@angular/core';
import { AbstractControl } from '@angular/forms';
import { MessageModule } from 'primeng/message';
import { UikitLabelComponent } from './uikit-label.component';
type PSize = 'small' | 'normal' | 'large';
@Component({
selector: 'uikit-field',
standalone: true,
imports: [CommonModule, UikitLabelComponent, MessageModule],
templateUrl: './uikit-field.component.html',
})
export class UikitFieldComponent {
@Input() label: string = '';
@Input() name!: string;
@Input() pSize: PSize = 'normal';
@Input() className?: string;
@Input() invalid?: boolean = false;
// accept a FormControl or AbstractControl to display errors for
@Input() control?: AbstractControl | null;
@Input() showErrors: boolean = true;
@Input() showLabel: boolean = true;
private errorsService = inject(FormErrorsService);
get hasError(): boolean {
if (!this.control) return !!this.invalid;
return !!(this.control.invalid && (this.control.touched || this.control.dirty));
}
get errors(): string[] {
if (!this.control) return this.invalid ? ['خطا'] : [];
return this.errorsService.getErrors(this.control, this.label).map((m) => m.message);
}
}