E. public / index.html

1
<!DOCTYPE html>
2
<html lang="es" class="light dark">
3
4
<head>
5
6
 <meta charset="UTF-8">
7
8
 <title>PWA con Formulario</title>
9
10
 <meta name="description" content="Ejemplo de PWA con Formulario">
11
12
 <script type="module" src="js/registraServiceWorker.js"></script>
13
 <script type="module" src="libclienteweb/manejaErrores.js"></script>
14
15
 <meta name="viewport" content="width=device-width">
16
 <meta name="theme-color" content="#fffbfe">
17
 <link rel="icon" sizes="32x32" href="favicon.ico">
18
 <link rel="manifest" href="site.webmanifest">
19
 <link rel="stylesheet" href="css/material-symbols-outlined.css">
20
 <link rel="stylesheet" href="material-tokens/css/baseline.css">
21
 <link rel="stylesheet" href="css/estilos.css">
22
 <script src="ungap/es.js"></script>
23
24
 <script type="module" src="libmde/md-app-bar.js"></script>
25
 <script type="module" src="js/nav-tab-fixed.js"></script>
26
27
 <link rel="stylesheet" href="libmde/md-tab.css">
28
 <link rel="stylesheet" href="libmde/md-filled-text-field.css">
29
 <link rel="stylesheet" href="libmde/md-filled-button.css">
30
 <link rel="stylesheet" href="libmde/md-outline-button.css">
31
 <link rel="stylesheet" href="css/transicion_pestanas.css">
32
33
</head>
34
35
<body>
36
37
 <form id="formulario" novalidate>
38
39
  <md-app-bar class="centered" adicional="tab">
40
41
   <h1>PWA con Formulario</h1>
42
43
  </md-app-bar>
44
45
  <nav-tab-fixed id="tab"></nav-tab-fixed>
46
47
  <section>
48
49
   <!-- Usa
50
    class="float"
51
   cuando quieras que la etiqueta esté arriba todo el tiempo. -->
52
   <p>
53
    <label class="md-filled-text-field float">
54
     <output name="respuesta">Todavía no hay respuesta</output>
55
     <span>Respuesta</span>
56
    </label>
57
   </p>
58
59
   <p>
60
    <label class="md-filled-text-field">
61
     <input name="nombre" required placeholder="Nombre*">
62
     <span>Nombre *</span>
63
     <small id="supportingNombre">Obligatorio</small>
64
    </label>
65
   </p>
66
67
   <p>
68
    <label class="md-filled-text-field">
69
     <input name="email" type="email" placeholder="Email">
70
     <span accesskey="M">Email</span>
71
     <small id="supportingEmail">Texto con formato de email</small>
72
    </label>
73
   </p>
74
75
   <p>
76
    <label class="md-filled-text-field float">
77
     <input name="fecha" type="date" placeholder="Fecha">
78
     <span>Fecha de nacimiento</span>
79
    </label>
80
   </p>
81
82
   <p>
83
    <label class="md-filled-text-field">
84
     <textarea name="dieccion" rows="3" placeholder="Dirección"></textarea>
85
     <span>Dirección</span>
86
    </label>
87
   </p>
88
89
   <p>
90
    <button id="botonSaludo" class="md-filled-button">Saludar</button>
91
    <button id="botonDatos" class="md-outline-button">Datos</button>
92
   </p>
93
94
  </section>
95
96
 </form>
97
98
 <script type="module">
99
100
  import { muestraTextoDeAyuda } from "./libclienteweb/muestraTextoDeAyuda.js"
101
102
  formulario.nombre.addEventListener("input", copiaMensajes)
103
  formulario.email.addEventListener("input", copiaMensajes)
104
  formulario.addEventListener("submit", procesa)
105
106
  function copiaMensajes() {
107
   muestraTextoDeAyuda(formulario.nombre, supportingNombre, "Obligatorio")
108
   muestraTextoDeAyuda(
109
    formulario.email, supportingEmail, "Texto con formato de email"
110
   )
111
  }
112
113
  /**
114
   * @param {SubmitEvent} evt
115
   */
116
  function procesa(evt) {
117
   evt.preventDefault()
118
   copiaMensajes()
119
   if (
120
    formulario.nombre.validity.valid
121
    && formulario.email.validity.valid
122
    && formulario.fecha.validity.valid
123
    && formulario.dieccion.validity.valid
124
   ) {
125
    const botonSeleccionado = evt.submitter
126
    if (botonSeleccionado === botonSaludo) {
127
     saluda()
128
    } else if (botonSeleccionado === botonDatos) {
129
     datos()
130
    }
131
   }
132
  }
133
134
  function saluda() {
135
   formulario.respuesta.value = `Hola ${formulario.nombre.value}`
136
  }
137
138
  function datos() {
139
   formulario.respuesta.value =
140
    `Nombre: ${formulario.nombre.value} Email: ${formulario.email.value}`
141
  }
142
143
 </script>
144
145
</body>
146
147
</html>
skip_previous skip_next