💄 Support Enter keypress to validate form
This commit is contained in:
parent
c9df0c6d33
commit
bc95aa98f0
@ -1,6 +1,6 @@
|
|||||||
<div pFocusTrap class="grid items-center gap-4" [formGroup]="categoryForm">
|
<div pFocusTrap class="grid items-center gap-4" [formGroup]="categoryForm">
|
||||||
<p-floatlabel variant="in">
|
<p-floatlabel variant="in">
|
||||||
<input id="name" formControlName="name" pInputText fluid />
|
<input id="name" formControlName="name" pInputText fluid (keyup.enter)="closeDialog()" />
|
||||||
<label for="name">Name</label>
|
<label for="name">Name</label>
|
||||||
</p-floatlabel>
|
</p-floatlabel>
|
||||||
|
|
||||||
|
|||||||
@ -49,6 +49,7 @@ export class CategoryCreateModalComponent {
|
|||||||
closeDialog() {
|
closeDialog() {
|
||||||
// Normalize data for API POST
|
// Normalize data for API POST
|
||||||
let ret = this.categoryForm.value;
|
let ret = this.categoryForm.value;
|
||||||
|
if (!ret["name"]) return;
|
||||||
if (!this.updatedImage) delete ret["image"];
|
if (!this.updatedImage) delete ret["image"];
|
||||||
this.ref.close(ret);
|
this.ref.close(ret);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<section>
|
<section>
|
||||||
<div [formGroup]="dayForm">
|
<div [formGroup]="dayForm">
|
||||||
<p-floatlabel variant="in">
|
<p-floatlabel variant="in">
|
||||||
<input id="label" formControlName="label" pInputText fluid />
|
<input id="label" formControlName="label" pInputText fluid (keyup.enter)="closeDialog()" />
|
||||||
<label for="label">Label</label>
|
<label for="label">Label</label>
|
||||||
</p-floatlabel>
|
</p-floatlabel>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
import { Component } from "@angular/core";
|
import { Component } from "@angular/core";
|
||||||
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from "@angular/forms";
|
import {
|
||||||
|
FormBuilder,
|
||||||
|
FormGroup,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
Validators,
|
||||||
|
} from "@angular/forms";
|
||||||
import { ButtonModule } from "primeng/button";
|
import { ButtonModule } from "primeng/button";
|
||||||
import { DynamicDialogConfig, DynamicDialogRef } from "primeng/dynamicdialog";
|
import { DynamicDialogConfig, DynamicDialogRef } from "primeng/dynamicdialog";
|
||||||
import { FloatLabelModule } from "primeng/floatlabel";
|
import { FloatLabelModule } from "primeng/floatlabel";
|
||||||
@ -8,7 +13,12 @@ import { TripDay } from "../../types/trip";
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-trip-create-day-modal",
|
selector: "app-trip-create-day-modal",
|
||||||
imports: [FloatLabelModule, InputTextModule, ButtonModule, ReactiveFormsModule],
|
imports: [
|
||||||
|
FloatLabelModule,
|
||||||
|
InputTextModule,
|
||||||
|
ButtonModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
],
|
||||||
standalone: true,
|
standalone: true,
|
||||||
templateUrl: "./trip-create-day-modal.component.html",
|
templateUrl: "./trip-create-day-modal.component.html",
|
||||||
styleUrl: "./trip-create-day-modal.component.scss",
|
styleUrl: "./trip-create-day-modal.component.scss",
|
||||||
@ -20,7 +30,7 @@ export class TripCreateDayModalComponent {
|
|||||||
constructor(
|
constructor(
|
||||||
private ref: DynamicDialogRef,
|
private ref: DynamicDialogRef,
|
||||||
private fb: FormBuilder,
|
private fb: FormBuilder,
|
||||||
private config: DynamicDialogConfig
|
private config: DynamicDialogConfig,
|
||||||
) {
|
) {
|
||||||
this.dayForm = this.fb.group({
|
this.dayForm = this.fb.group({
|
||||||
id: -1,
|
id: -1,
|
||||||
@ -37,6 +47,7 @@ export class TripCreateDayModalComponent {
|
|||||||
closeDialog() {
|
closeDialog() {
|
||||||
// Normalize data for API POST
|
// Normalize data for API POST
|
||||||
let ret = this.dayForm.value;
|
let ret = this.dayForm.value;
|
||||||
|
if (!ret["label"]) return;
|
||||||
this.ref.close(ret);
|
this.ref.close(ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<div pFocusTrap class="grid items-center gap-4" [formGroup]="tripForm">
|
<div pFocusTrap class="grid items-center gap-4" [formGroup]="tripForm">
|
||||||
<p-floatlabel variant="in">
|
<p-floatlabel variant="in">
|
||||||
<input id="name" formControlName="name" pInputText fluid />
|
<input id="name" formControlName="name" pInputText fluid (keyup.enter)="closeDialog()" />
|
||||||
<label for="name">Name</label>
|
<label for="name">Name</label>
|
||||||
</p-floatlabel>
|
</p-floatlabel>
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
import { Component } from "@angular/core";
|
import { Component } from "@angular/core";
|
||||||
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from "@angular/forms";
|
import {
|
||||||
|
FormBuilder,
|
||||||
|
FormGroup,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
Validators,
|
||||||
|
} from "@angular/forms";
|
||||||
import { ButtonModule } from "primeng/button";
|
import { ButtonModule } from "primeng/button";
|
||||||
import { DynamicDialogConfig, DynamicDialogRef } from "primeng/dynamicdialog";
|
import { DynamicDialogConfig, DynamicDialogRef } from "primeng/dynamicdialog";
|
||||||
import { FloatLabelModule } from "primeng/floatlabel";
|
import { FloatLabelModule } from "primeng/floatlabel";
|
||||||
@ -8,7 +13,13 @@ import { FocusTrapModule } from "primeng/focustrap";
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-trip-create-modal",
|
selector: "app-trip-create-modal",
|
||||||
imports: [FloatLabelModule, InputTextModule, ButtonModule, ReactiveFormsModule, FocusTrapModule],
|
imports: [
|
||||||
|
FloatLabelModule,
|
||||||
|
InputTextModule,
|
||||||
|
ButtonModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
FocusTrapModule,
|
||||||
|
],
|
||||||
standalone: true,
|
standalone: true,
|
||||||
templateUrl: "./trip-create-modal.component.html",
|
templateUrl: "./trip-create-modal.component.html",
|
||||||
styleUrl: "./trip-create-modal.component.scss",
|
styleUrl: "./trip-create-modal.component.scss",
|
||||||
@ -21,7 +32,7 @@ export class TripCreateModalComponent {
|
|||||||
constructor(
|
constructor(
|
||||||
private ref: DynamicDialogRef,
|
private ref: DynamicDialogRef,
|
||||||
private fb: FormBuilder,
|
private fb: FormBuilder,
|
||||||
private config: DynamicDialogConfig
|
private config: DynamicDialogConfig,
|
||||||
) {
|
) {
|
||||||
this.tripForm = this.fb.group({
|
this.tripForm = this.fb.group({
|
||||||
id: -1,
|
id: -1,
|
||||||
@ -40,6 +51,7 @@ export class TripCreateModalComponent {
|
|||||||
closeDialog() {
|
closeDialog() {
|
||||||
// Normalize data for API POST
|
// Normalize data for API POST
|
||||||
let ret = this.tripForm.value;
|
let ret = this.tripForm.value;
|
||||||
|
if (!ret["name"]) return;
|
||||||
if (ret["image_id"]) {
|
if (ret["image_id"]) {
|
||||||
delete ret["image"];
|
delete ret["image"];
|
||||||
delete ret["image_id"];
|
delete ret["image_id"];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user