Advertisement
xxxxbe

reactiveFRM

Jun 30th, 2020
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, Input, OnInit  } from '@angular/core';
  2. import { FormGroup, FormBuilder, Validators } from '@angular/forms';
  3.  
  4. @Component({
  5.   selector: 'app-dashboard-schedule',
  6.   templateUrl: './dashboard-schedule.component.html',
  7.   styleUrls: ['./dashboard-schedule.component.scss']
  8. })
  9.  
  10. export class DashboardScheduleComponent implements OnInit {
  11.   @Input() title: string = 'Horario del restaurante';
  12.   @Input() subtitle: string = 'Horario del restaurante en la semana';
  13.   @Input() day_wk_a: string = 'Lunes a viernes';
  14.   @Input() day_wk_b: string = 'Sabado';
  15.   @Input() day_wk_c: string = 'Domingo';
  16.   @Input() from_sche: string = 'Desde:';
  17.   @Input() to_sche: string = 'Hasta:';
  18.   @Input() day_fes: string = 'Día';
  19.   @Input() day_des: string = 'Descripción';
  20.   @Input() name_main: string = 'Nombre';
  21.   @Input() btn_submit: string = 'Enviar';
  22.   @Input() title_fes: string = 'Días festivos';
  23.   scheduleForm: FormGroup;
  24.   submitted = false;
  25.  
  26.   constructor(private formBuilder: FormBuilder) { }
  27.  
  28.    public ngOnInit(): void {
  29.      this.scheduleForm = this.formBuilder.group({
  30.       mondayFridayFrm: ['12:00', Validators.required],
  31.       mondayFridayTo: ['12:00', Validators.required],
  32.       saturdayFrm: ['12:00', Validators.required],
  33.       saturdayTo: ['12:00', Validators.required],
  34.       sundayFrm: ['12:00', Validators.required],
  35.       sundayTo: ['12:00', Validators.required],
  36.       celebration: ['Navidad', Validators.required],
  37.       celebrationDescription: ['Celebración de navidad', Validators.required],
  38.       dateM: ['24/12/2020', Validators.required]
  39.      })
  40.   }
  41.  
  42.  
  43.   get f() { return this.scheduleForm.controls; }
  44.  
  45.   public onSubmit() {
  46.     this.submitted = true;
  47.  
  48.         if (this.scheduleForm.invalid) {
  49.           return;
  50.       }
  51.  
  52.       alert('Data\n' + JSON.stringify(this.scheduleForm.value))
  53.   }
  54.  
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement