|
|
@@ -3,7 +3,7 @@ import { Component, OnInit } from '@angular/core';
|
|
|
import { EnviarInfoService } from '../../services/enviar-info.service';
|
|
|
import { FormService } from '../../services/FormService.service';
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
-import { FormArray } from '@angular/forms';
|
|
|
+import { FormArray, Validators } from '@angular/forms';
|
|
|
import { FormBuilder, FormGroup, FormControl } from '@angular/forms';
|
|
|
|
|
|
//aqui es para agregar popiedades a las celdas que se generan el el build grid
|
|
|
@@ -176,6 +176,15 @@ export class AdminFormComponent implements OnInit {
|
|
|
];
|
|
|
formData: any;
|
|
|
form: any;
|
|
|
+ // Dentro del AdminFormComponent (fuera de métodos)
|
|
|
+
|
|
|
+showModalIdentificador = false;
|
|
|
+nombreIdentificadorControl = new FormControl('', [
|
|
|
+ Validators.required,
|
|
|
+ Validators.pattern('^[a-zA-Z_][a-zA-Z0-9_]*$')
|
|
|
+]);
|
|
|
+pendingTemplate: FormElement | null = null;
|
|
|
+
|
|
|
|
|
|
constructor(
|
|
|
private _enviarInfo: EnviarInfoService,
|
|
|
@@ -562,30 +571,20 @@ getSafeControlName(cell: any, rowIndex: number, colIndex: number): string {
|
|
|
this.editingElement = null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-addElementToCell(template: FormElement) {
|
|
|
- if (!this.selectedCell || this.selectedCell.element) {
|
|
|
- alert('Esta celda ya tiene un campo. Elimínalo primero.');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Solicita un "nombre clave" legible para el input, ejemplo: "nombre_alumno"
|
|
|
- let nombreClave = prompt('Ingresa el identificador único para este campo (ej. nombre_alumno):');
|
|
|
- if (!nombreClave) {
|
|
|
- alert('Debes ingresar un identificador válido.');
|
|
|
+confirmarIdentificador() {
|
|
|
+ if (this.nombreIdentificadorControl.invalid || !this.pendingTemplate) {
|
|
|
+ this.nombreIdentificadorControl.markAsTouched();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // Limpia espacios y pasa a minúsculas para usar como key
|
|
|
- nombreClave = nombreClave.trim().toLowerCase().replace(/\s+/g, '_');
|
|
|
-
|
|
|
- const element = { ...template };
|
|
|
+ const nombreClave = this.nombreIdentificadorControl.value!.trim().toLowerCase().replace(/\s+/g, '_');
|
|
|
+ const element = { ...this.pendingTemplate };
|
|
|
|
|
|
element.id = `${this.currentTab?.id}_${nombreClave}`;
|
|
|
- element.name = nombreClave; // <--- Aquí asignamos el key legible
|
|
|
- element.label = this.capitalizeWords(nombreClave.replace(/_/g, ' ')); // etiqueta legible: "Nombre Alumno"
|
|
|
+ element.name = nombreClave;
|
|
|
+ element.label = this.capitalizeWords(nombreClave.replace(/_/g, ' '));
|
|
|
|
|
|
- // Aplica validaciones según tipo, igual que antes
|
|
|
+ // Validaciones según tipo
|
|
|
switch (element.type) {
|
|
|
case 'email':
|
|
|
Object.assign(element, {
|
|
|
@@ -598,19 +597,74 @@ addElementToCell(template: FormElement) {
|
|
|
Object.assign(element, { required: true, min: 1, max: 100 });
|
|
|
break;
|
|
|
case 'text':
|
|
|
- element.required = true;
|
|
|
- element.min = element.min ?? 1;
|
|
|
- element.max = element.max ?? 20;
|
|
|
- if (!element.pattern) {
|
|
|
- element.pattern = '^\\b(\\w+\\b\\s*){1,20}$';
|
|
|
- }
|
|
|
+ element.required = true;
|
|
|
+ element.min = element.min ?? 1;
|
|
|
+ element.max = element.max ?? 20;
|
|
|
+ if (!element.pattern) {
|
|
|
+ element.pattern = '^\\b(\\w+\\b\\s*){1,20}$';
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- this.selectedCell.element = element;
|
|
|
+ this.selectedCell!.element = element;
|
|
|
this.editingElement = element;
|
|
|
this.showElementSelector = false;
|
|
|
this.updateCurrentTabGrid();
|
|
|
+ this.showModalIdentificador = false;
|
|
|
+ this.pendingTemplate = null;
|
|
|
+}
|
|
|
+
|
|
|
+addElementToCell(template: FormElement) {
|
|
|
+ if (!this.selectedCell || this.selectedCell.element) {
|
|
|
+ alert('Esta celda ya tiene un campo. Elimínalo primero.');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.pendingTemplate = template;
|
|
|
+ this.nombreIdentificadorControl.reset();
|
|
|
+ this.showModalIdentificador = true; // abre modal
|
|
|
+
|
|
|
+ // // Solicita un "nombre clave" legible para el input, ejemplo: "nombre_alumno"
|
|
|
+ // let nombreClave = prompt('Ingresa el identificador único para este campo (ej. nombre_alumno):');
|
|
|
+ // if (!nombreClave) {
|
|
|
+ // alert('Debes ingresar un identificador válido.');
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // // Limpia espacios y pasa a minúsculas para usar como key
|
|
|
+ // nombreClave = nombreClave.trim().toLowerCase().replace(/\s+/g, '_');
|
|
|
+
|
|
|
+ // const element = { ...template };
|
|
|
+
|
|
|
+ // element.id = `${this.currentTab?.id}_${nombreClave}`;
|
|
|
+ // element.name = nombreClave; // <--- Aquí asignamos el key legible
|
|
|
+ // element.label = this.capitalizeWords(nombreClave.replace(/_/g, ' ')); // etiqueta legible: "Nombre Alumno"
|
|
|
+
|
|
|
+ // Aplica validaciones según tipo, igual que antes
|
|
|
+ // switch (element.type) {
|
|
|
+ // case 'email':
|
|
|
+ // Object.assign(element, {
|
|
|
+ // required: true,
|
|
|
+ // pattern: '^[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,}$',
|
|
|
+ // placeholder: 'ejemplo@correo.com'
|
|
|
+ // });
|
|
|
+ // break;
|
|
|
+ // case 'number':
|
|
|
+ // Object.assign(element, { required: true, min: 1, max: 100 });
|
|
|
+ // break;
|
|
|
+ // case 'text':
|
|
|
+ // element.required = true;
|
|
|
+ // element.min = element.min ?? 1;
|
|
|
+ // element.max = element.max ?? 20;
|
|
|
+ // if (!element.pattern) {
|
|
|
+ // element.pattern = '^\\b(\\w+\\b\\s*){1,20}$';
|
|
|
+ // }
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // this.selectedCell.element = element;
|
|
|
+ // this.editingElement = element;
|
|
|
+ this.showElementSelector = false;
|
|
|
+ this.updateCurrentTabGrid();
|
|
|
}
|
|
|
getControlName(tab: Tab | null, cell: any): string {
|
|
|
const row = cell.row ?? 0;
|