Browse Source

feat: add validation in the forms of the product page

pull/34/head
bnymncoskuner 5 years ago
parent
commit
d2214d1226
  1. 18
      apps/angular/projects/catalog/src/pages/product/product.component.html
  2. 10
      apps/angular/projects/catalog/src/pages/product/product.component.ts
  3. 10
      apps/angular/projects/catalog/src/pages/product/product.module.ts

18
apps/angular/projects/catalog/src/pages/product/product.component.html

@ -13,7 +13,6 @@
</div> </div>
<div class="card-body"> <div class="card-body">
<ngx-datatable [rows]="items" [count]="count" [list]="list" default> <ngx-datatable [rows]="items" [count]="count" [list]="list" default>
<!-- TODO: localize column headers -->
<ngx-datatable-column <ngx-datatable-column
[name]="'AbpUi::Actions' | abpLocalization" [name]="'AbpUi::Actions' | abpLocalization"
[sortable]="false" [sortable]="false"
@ -83,53 +82,54 @@
<form *ngIf="form; else loaderRef" [formGroup]="form" (ngSubmit)="save()"> <form *ngIf="form; else loaderRef" [formGroup]="form" (ngSubmit)="save()">
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="code"> <label class="form-label" for="code">
{{ 'CatalogService::DisplayName:Code' | abpLocalization }} {{ 'CatalogService::DisplayName:Code' | abpLocalization }} *
</label> </label>
<input <input
type="text" type="text"
class="form-control" class="form-control"
id="code" id="code"
formControlName="code" formControlName="code"
placeholder="{{ 'CatalogService::DisplayName:Code' | abpLocalization }}" [readonly]="selected?.id"
[placeholder]="'CatalogService::DisplayName:Code' | abpLocalization"
/> />
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="name"> <label class="form-label" for="name">
{{ 'CatalogService::DisplayName:Name' | abpLocalization }} {{ 'CatalogService::DisplayName:Name' | abpLocalization }} *
</label> </label>
<input <input
type="text" type="text"
class="form-control" class="form-control"
id="name" id="name"
formControlName="name" formControlName="name"
placeholder="{{ 'CatalogService::DisplayName:Name' | abpLocalization }}" [placeholder]="'CatalogService::DisplayName:Name' | abpLocalization"
/> />
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="price"> <label class="form-label" for="price">
{{ 'CatalogService::DisplayName:Price' | abpLocalization }} {{ 'CatalogService::DisplayName:Price' | abpLocalization }} *
</label> </label>
<input <input
type="number" type="number"
class="form-control" class="form-control"
id="price" id="price"
formControlName="price" formControlName="price"
placeholder="{{ 'CatalogService::DisplayName:Price' | abpLocalization }}" [placeholder]="'CatalogService::DisplayName:Price' | abpLocalization"
/> />
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="stockCount"> <label class="form-label" for="stockCount">
{{ 'CatalogService::DisplayName:StockCount' | abpLocalization }} {{ 'CatalogService::DisplayName:StockCount' | abpLocalization }} *
</label> </label>
<input <input
type="number" type="number"
class="form-control" class="form-control"
id="stockCount" id="stockCount"
formControlName="stockCount" formControlName="stockCount"
placeholder="{{ 'CatalogService::DisplayName:StockCount' | abpLocalization }}" [placeholder]="'CatalogService::DisplayName:StockCount' | abpLocalization"
/> />
</div> </div>
</form> </form>

10
apps/angular/projects/catalog/src/pages/product/product.component.ts

@ -1,7 +1,7 @@
import { ListService } from '@abp/ng.core'; import { ListService } from '@abp/ng.core';
import { Confirmation, ConfirmationService } from '@abp/ng.theme.shared'; import { Confirmation, ConfirmationService } from '@abp/ng.theme.shared';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { eCatalogPolicyNames } from '@catalog/config'; import { eCatalogPolicyNames } from '@catalog/config';
import { ProductDto, ProductService } from '@catalog/proxy/products'; import { ProductDto, ProductService } from '@catalog/proxy/products';
import { finalize } from 'rxjs/operators'; import { finalize } from 'rxjs/operators';
@ -49,10 +49,10 @@ export class ProductComponent implements OnInit {
buildForm() { buildForm() {
this.form = this.fb.group({ this.form = this.fb.group({
name: [this.selected.name], name: [this.selected.name, { validators: [Validators.required] }],
code: [this.selected.code], code: [this.selected.code, { validators: [Validators.required] }],
price: [this.selected.price], price: [this.selected.price, { validators: [Validators.required] }],
stockCount: [this.selected.stockCount], stockCount: [this.selected.stockCount, { validators: [Validators.required] }],
}); });
} }

10
apps/angular/projects/catalog/src/pages/product/product.module.ts

@ -3,11 +3,19 @@ import { ThemeSharedModule } from '@abp/ng.theme.shared';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';
import { NgxValidateCoreModule } from '@ngx-validate/core';
import { ProductRoutingModule } from './product-routing.module'; import { ProductRoutingModule } from './product-routing.module';
import { ProductComponent } from './product.component'; import { ProductComponent } from './product.component';
@NgModule({ @NgModule({
declarations: [ProductComponent], declarations: [ProductComponent],
imports: [CommonModule, ProductRoutingModule, ThemeSharedModule, CoreModule, NgbDropdownModule], imports: [
CommonModule,
ProductRoutingModule,
ThemeSharedModule,
CoreModule,
NgbDropdownModule,
NgxValidateCoreModule,
],
}) })
export class ProductModule {} export class ProductModule {}

Loading…
Cancel
Save