freeCodeCamp/curriculum/challenges/espanol/01-responsive-web-design/basic-html-and-html5/use-html5-to-require-a-fiel...

2.3 KiB

id title challengeType videoUrl forumTopicId dashedName
bad87fee1348bd9aedc08830 Usa HTML5 para requerir un campo 0 https://scrimba.com/p/pVMPUv/cMd4EcQ 18360 use-html5-to-require-a-field

--description--

Puedes requerir campos específicos de un formulario para que tu usuario no pueda enviarlo hasta que no los haya rellenado.

Por ejemplo, si deseas hacer obligatorio un campo de entrada de texto, puedes agregar el atributo required dentro de tu elemento input, de esta forma: <input type="text" required>

--instructions--

Convierte tu entrada de texto input en un campo obligatorio required para que tu usuario no pueda enviar el formulario sin completar este campo.

Luego intenta enviar el formulario sin introducir ningún texto. ¿Ves cómo tu formulario HTML5 te notifica que el campo es obligatorio?

--hints--

Tu elemento de entrada de texto input debe tener el atributo required.

assert($('input').prop('required'));

--seed--

--seed-contents--

<h2>CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>

  <a href="#"><img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt="A cute orange cat lying on its back."></a>

  <p>Things cats love:</p>
  <ul>
    <li>cat nip</li>
    <li>laser pointers</li>
    <li>lasagna</li>
  </ul>
  <p>Top 3 things cats hate:</p>
  <ol>
    <li>flea treatment</li>
    <li>thunder</li>
    <li>other cats</li>
  </ol>
  <form action="https://www.freecatphotoapp.com/submit-cat-photo">
    <input type="text" placeholder="cat photo URL">
    <button type="submit">Submit</button>
  </form>
</main>

--solutions--

<h2>CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>

  <a href="#"><img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt="A cute orange cat lying on its back."></a>

  <p>Things cats love:</p>
  <ul>
    <li>cat nip</li>
    <li>laser pointers</li>
    <li>lasagna</li>
  </ul>
  <p>Top 3 things cats hate:</p>
  <ol>
    <li>flea treatment</li>
    <li>thunder</li>
    <li>other cats</li>
  </ol>
  <form action="https://www.freecatphotoapp.com/submit-cat-photo">
    <input type="text" required placeholder="cat photo URL">
    <button type="submit">Submit</button>
  </form>
</main>