πŸ’» FE/πŸ“ HTML & CSS

HTML 폼 νƒœκ·Έμ— λŒ€ν•΄μ„œ μ•„μ‹œλ‚˜μš”? μ €λŠ” μ•ŒκΈ΄ μ•„λŠ”λ°μš”? (not 폼폼푸린)

Roy Miller 2025. 3. 7. 13:06

 

폼 (폼푸린)

<form action="" method="get" class="form-example">
  <div class="form-example">
    <label for="name">Enter your name: </label>
    <input type="text" name="name" id="name" required />
  </div>
  <div class="form-example">
    <label for="email">Enter your email: </label>
    <input type="email" name="email" id="email" required />
  </div>
  <div class="form-example">
    <input type="submit" value="Subscribe!" />
  </div>
</form>

 

πŸ“Œ action, method

 

action

  • 양식 데이터λ₯Ό μ²˜λ¦¬ν•  ν”„λ‘œκ·Έλž¨μ˜ URI μ§€μ •
  • <button>, <input type="submit">, <input type="image"> μš”μ†Œμ˜ formaction νŠΉμ„±μœΌλ‘œ μž¬μ •μ˜ κ°€λŠ₯

 

method

  • 양식을 μ œμΆœν•  λ•Œ μ‚¬μš©ν•  HTTP λ©”μ„œλ“œ.
  • post: POST λ©”μ„œλ“œ. 양식 데이터λ₯Ό μš”μ²­ 본문으둜 전솑
  • get: GET λ©”μ„œλ“œ. 양식 데이터λ₯Ό action URLκ³Ό ? κ΅¬λΆ„μž 뒀에 이어 λΆ™μ—¬μ„œ 전솑
    • 검색에 μ‚¬μš©
  • dialog: 양식이 <dialog> μ•ˆμ— μœ„μΉ˜ν•œ 경우, 제좜과 ν•¨κ»˜ λŒ€ν™” μƒμžλ₯Ό λ‹«μŒ
  • <button>, <input type="submit">, <input type="image"> μš”μ†Œμ˜ formmethod νŠΉμ„±μœΌλ‘œ μž¬μ •μ˜ κ°€λŠ₯
<!-- Form which will send a GET request to the current URL -->
<form>
  <label
    >Name:
    <input name="submitted-name" autocomplete="name" />
  </label>
  <button>Save</button>
</form>

<!-- Form which will send a POST request to the current URL -->
<form method="post">
  <label
    >Name:
    <input name="submitted-name" autocomplete="name" />
  </label>
  <button>Save</button>
</form>

<!-- Form with fieldset, legend, and label -->
<form method="post">
  <fieldset>
    <legend>Title</legend>
    <label><input type="radio" name="radio" /> Select me</label>
  </fieldset>
</form>

 

 

πŸ“Œ fieldset, legend

<form>
  <fieldset>
    <legend>Choose your favorite monster</legend>

    <input type="radio" id="kraken" name="monster" value="K" />
    <label for="kraken">Kraken</label><br />

    <input type="radio" id="sasquatch" name="monster" value="S" />
    <label for="sasquatch">Sasquatch</label><br />

    <input type="radio" id="mothman" name="monster" value="M" />
    <label for="mothman">Mothman</label>
  </fieldset>
</form>

 

<fieldset> μŠ€νƒ€μΌλ§

  • <fieldset>의 display μ†μ„±μ˜ 값은 기본적으둜 block이며,
  • μΈλΌμΈν˜• display 값을 μ§€μ •ν•˜λ©΄ inline-block, κ·Έλ ‡μ§€ μ•ŠμœΌλ©΄ block처럼 행동

 

  • <fieldset>은 κΈ°λ³Έ μŠ€νƒ€μΌλ‘œ μ½˜ν…μΈ λ₯Ό κ°μ‹ΈλŠ” 2px λ„ˆλΉ„μ˜ groove ν…Œλ‘λ¦¬, μž‘μ€ μ–‘μ˜ λ‚΄λΆ€ μ—¬λ°±, 그리고 min-inline-size: min-contentλ₯Ό 가짐
  • <legend> μš”μ†ŒλŠ” <fieldset>의 블둝 μ‹œμž‘ λ°©ν–₯(λŒ€κ°œ μœ„μͺ½) ν…Œλ‘λ¦¬ μœ„λ₯Ό κ°€λ‘œμ§€λ₯΄λŠ” μœ„μΉ˜μ— λ†“μž„
  • <legend> λ˜ν•œ μžμ‹ μ˜ 블둝 μ„œμ‹ λ§₯락을 λ§Œλ“€λ©°, λ„ˆλΉ„λŠ” μžμ‹ μ˜ μ½˜ν…μΈ μ— 맞좰져 λŠ˜μ–΄λ‚˜κ±°λ‚˜ 쀄어듬
  • displayλŠ” 항상 λΈ”λ‘ν˜•μ΄ 됨. 즉, display: inline도 block처럼 λ™μž‘

 

  • Microsoft Edge와 Google Chromeμ—λŠ” <fieldset> λ‚΄λΆ€μ—μ„œ ν”Œλ ‰μŠ€λ°•μŠ€μ™€ κ·Έλ¦¬λ“œ λ ˆμ΄μ•„μ›ƒμ„ μ‚¬μš©ν•  수 μ—†λŠ” 버그가 쑴재.

 

πŸ“Œ input , type

 

Category Type Description
Text input types text Single-line text input.
  password Password input (obscures the text).
  email Email input (validates email addresses).
  url URL input (validates URLs).
  number Numeric input (accepts numbers only).
  range Numeric input with a specified range.
  date Date input (accepts dates in a specified format).
  datetime-local Date and time input (accepts date and time in a specified format).
  month Month input (accepts months).
  week Week input (accepts weeks).
  time Time input (accepts times).
Checkbox input types checkbox Checkbox input (single selection).
  radio Radio button input (single selection from a group).
File input types file File input (allows users to upload files).
Button input types button Button input (submits a form or triggers an action).
  reset Reset button input (resets a form).
  submit Submit button input (submits a form).
Other input types color Color input (allows users to select a color).
  image Image input (allows users to upload an image).
  range Range input (allows users to select a value from a range).
  search Search input (allows users to search for something).
  tel Telephone input (accepts phone numbers).
  textarea Multi-line text input.
<label for="name">Name (4 to 8 characters):</label>

<input
  type="text"
  id="name"
  name="name"
  required
  minlength="4"
  maxlength="8"
  size="10" />
  • label의 forκ³Ό input의 id와 연결됨.
  • lable의 μžμ‹μœΌλ‘œ λ„£μœΌλ©΄ for μ•ˆ 해도 됨.

 

πŸ“Œ μ²΄ν¬λ°•μŠ€

<form>
  <div>
    <input
      type="checkbox"
      id="subscribeNews"
      name="subscribe"
      value="newsletter" />
    <label for="subscribeNews">λ‰΄μŠ€λ ˆν„°λ₯Ό κ΅¬λ…ν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?</label>
  </div>
  <div>
    <button type="submit">κ΅¬λ…ν•˜κΈ°</button>
  </div>
</form>
  • name νŠΉμ„±μ€ subscribe둜, value νŠΉμ„±μ€ newsletter으둜 μ§€μ •
  • 폼이 제좜되면 전달될 name/value 쌍의 λ°μ΄ν„°λŠ” subscribe=newsletter와 같이 ν‘œν˜„

 

  • λ§Œμ•½ value νŠΉμ„±μ΄ μƒλž΅λ˜λ©΄, ν•΄λ‹Ή μ²΄ν¬λ°•μŠ€μ˜ κΈ°λ³Έ 값은 on
  • 폼이 제좜될 λ•Œ μ²΄ν¬λ°•μŠ€κ°€ μ²΄ν¬λ˜μ–΄ μžˆμ§€ μ•ŠμœΌλ©΄ κ°’ μžμ²΄κ°€ μ„œλ²„μ— μ „λ‹¬λ˜μ§€ μ•ŠμŒ.

 

  • λΌλ””μ˜€ λ²„νŠΌμ€ ν•˜λ‚˜μ˜ μ§‘ν•©μœΌλ‘œ κ·Έλ£Ήν™”λ˜μ–΄ κ·Έ μ•ˆμ—μ„œ 단 ν•˜λ‚˜λ§Œ 선택될 수 μžˆμ§€λ§Œ,
  • μ²΄ν¬λ°•μŠ€μ˜ κ²½μš°λŠ” 각각의 값을 켜고 끌 수 있음. λ‹€μˆ˜μ˜ 컨트둀이 μ‘΄μž¬ν•  λ•Œ λΌλ””μ˜€ λ²„νŠΌμ€ μ „μ²΄μ—μ„œ ν•˜λ‚˜μ˜ μš”μ†Œμ— λŒ€ν•œ μ„ νƒλ§Œμ„ ν—ˆμš©ν•˜κ³ , μ²΄ν¬λ°•μŠ€λŠ” μ—¬λŸ¬ 개의 μš”μ†Œκ°€ μ„ νƒλ˜λŠ” 것을 ν—ˆμš©

 

πŸ“Œ 쀑간 μƒνƒœ μ²΄ν¬λ°•μŠ€

 

  • Javascript의 HTMLInputElement 객체의 indeterminate νŠΉμ„±μ— μ˜ν•΄ μ„€μ •
  • HTML νŠΉμ„±μ„ μ΄μš©ν•΄μ„œλŠ” μ„€μ •ν•  수 μ—†μŒ

 

js

inputInstance.indeterminate = true;

 

indeterminate μƒνƒœμ— μžˆλŠ” μ²΄ν¬λ°•μŠ€λŠ” λŒ€λΆ€λΆ„μ˜ λΈŒλΌμš°μ €μ—μ„œ μˆ˜ν‰μ„ μ„ 가짐.

 

  •  μ²΄ν¬λ°•μŠ€κ°€ μ—¬λŸ¬ ν•˜μœ„ μ²΄ν¬λ°•μŠ€λ₯Ό κ°€μ§€λŠ” 경우
  • λͺ¨λ“  ν•˜μœ„ μ²΄ν¬λ°•μŠ€κ°€ ν™œμ„±ν™”λ˜λ©΄, μƒμœ„ μ²΄ν¬λ°•μŠ€ λ˜ν•œ ν™œμ„±ν™”
  • ν•˜μœ„ μ²΄ν¬λ°•μŠ€ 쀑 ν•˜λ‚˜κ°€ λ‹€λ₯Έ μ²΄ν¬λ°•μŠ€λ“€κ³ΌλŠ” λ‹€λ₯Έ μƒνƒœλ₯Ό κ°€μ§„λ‹€λ©΄ μƒμœ„ μ²΄ν¬λ°•μŠ€λŠ” indeterminate μƒνƒœ
const overall = document.querySelector("#enchantment");
const ingredients = document.querySelectorAll("ul input");

overall.addEventListener("click", (e) => {
  e.preventDefault();
});

for (const ingredient of ingredients) {
  ingredient.addEventListener("click", updateDisplay);
}

function updateDisplay() {
  let checkedCount = 0;
  for (const ingredient of ingredients) {
    if (ingredient.checked) {
      checkedCount++;
    }
  }

  if (checkedCount === 0) {
    overall.checked = false;
    overall.indeterminate = false;
  } else if (checkedCount === ingredients.length) {
    overall.checked = true;
    overall.indeterminate = false;
  } else {
    overall.checked = false;
    overall.indeterminate = true;
  }
}

 

πŸ“Œ λΌλ””μ˜€ λ°•μŠ€

λΌλ””μ˜€ λ²„νŠΌ vs μ²΄ν¬λ°•μŠ€:

  • λΌλ””μ˜€ λ²„νŠΌ: μ—¬λŸ¬ μ˜΅μ…˜ 쀑 ν•˜λ‚˜λ§Œ 선택
  • μ²΄ν¬λ°•μŠ€: μ—¬λŸ¬ μ˜΅μ…˜ 쀑 μ—¬λŸ¬ 개 선택 κ°€λŠ₯

κ°’ (value 속성):

  • λΌλ””μ˜€ λ²„νŠΌμ˜ 값을 λ‚˜νƒ€λ‚΄λŠ” λ¬Έμžμ—΄
  • μ‚¬μš©μžμ—κ²ŒλŠ” ν‘œμ‹œλ˜μ§€ μ•ŠμŒ
  • μ„ νƒλœ λΌλ””μ˜€ λ²„νŠΌ 식별에 μ‚¬μš©

λΌλ””μ˜€ κ·Έλ£Ή:

  • λ™μΌν•œ name 속성을 κ°€μ§„ λΌλ””μ˜€ λ²„νŠΌλ“€μ˜ κ·Έλ£Ή
  • κ·Έλ£Ή λ‚΄μ—μ„œ ν•˜λ‚˜μ˜ λΌλ””μ˜€ λ²„νŠΌλ§Œ 선택 κ°€λŠ₯
  • μ—¬λŸ¬ λΌλ””μ˜€ κ·Έλ£Ή μ‚¬μš© κ°€λŠ₯ (각 그룹은 κ³ μœ ν•œ name ν•„μš”)
<input type="radio" name="contact" value="email"> Email
<input type="radio" name="contact" value="phone"> Phone
<input type="radio" name="contact" value="mail"> Mail

The resulting HTML looks like this:

```html
<form>
  <fieldset>
    <legend>Please select your preferred contact method:</legend>
    <div>
      <input type="radio" id="contactChoice1" name="contact" value="email" />
      <label for="contactChoice1">Email</label>

      <input type="radio" id="contactChoice2" name="contact" value="phone" />
      <label for="contactChoice2">Phone</label>

      <input type="radio" id="contactChoice3" name="contact" value="mail" />
      <label for="contactChoice3">Mail</label>
    </div>
    <div>
      <button type="submit">Submit</button>
    </div>
  </fieldset>
</form>
  • name 속성:
    • μ„Έ 개의 λΌλ””μ˜€ λ²„νŠΌ λͺ¨λ‘ contact둜 μ„€μ •λ˜μ–΄ ν•˜λ‚˜μ˜ 그룹을 ν˜•μ„±
  • value 속성:
    • 각 λΌλ””μ˜€ λ²„νŠΌμ€ κ·Έλ£Ή λ‚΄μ—μ„œ κ³ μœ ν•˜κ²Œ μ‹λ³„λ˜λŠ” value 값을 가짐
  • id 속성:
    • 각 λΌλ””μ˜€ λ²„νŠΌμ€ κ³ μœ ν•œ idλ₯Ό κ°€μ§€λ©°, μ΄λŠ” <label> μš”μ†Œμ˜ for 속성을 톡해 λΌλ””μ˜€ λ²„νŠΌκ³Ό λ ˆμ΄λΈ”μ„ μ—°κ²°ν•˜λŠ” 데 μ‚¬μš©
  • <label> μš”μ†Œ:
    • for 속성을 μ‚¬μš©ν•˜μ—¬ 각 λΌλ””μ˜€ λ²„νŠΌμ˜ id와 μ—°κ²°λ˜μ–΄, λ ˆμ΄λΈ”μ„ ν΄λ¦­ν–ˆμ„ λ•Œ ν•΄λ‹Ή λΌλ””μ˜€ λ²„νŠΌμ΄ 선택

 

πŸ“Œ button

  • <button> μš”μ†ŒλŠ” HTMLμ—μ„œ 클릭 κ°€λŠ₯ν•œ λ²„νŠΌμ„ μ •μ˜
  • μ‚¬μš©μž μΈν„°νŽ˜μ΄μŠ€(UI)μ—μ„œ νŠΉμ • λ™μž‘μ„ νŠΈλ¦¬κ±°ν•˜λŠ” 데 μ‚¬μš©

<a> μš”μ†Œμ™€μ˜ 차이점

νŠΉμ§• <button> <a>
μš©λ„ ν˜„μž¬ νŽ˜μ΄μ§€ λ‚΄ μƒν˜Έμž‘μš© (폼 제좜 λ“±) λ‹€λ₯Έ νŽ˜μ΄μ§€/μœ„μΉ˜λ‘œ 이동 (ν•˜μ΄νΌλ§ν¬)
폼 데이터 전솑 κ°€λŠ₯ (κ°’ 가짐) λΆˆκ°€λŠ₯
주둜 μ‚¬μš©ν•˜λŠ” 상황 슀크립트 μ‹€ν–‰ νŽ˜μ΄μ§€ 이동

 

핡심 속성

  • type: λ²„νŠΌμ˜ λ™μž‘ μœ ν˜• μ§€μ •.
    • submit (κΈ°λ³Έκ°’): 폼 제좜.
    • reset: 폼 ν•„λ“œ μ΄ˆκΈ°ν™”.
    • button: 일반 λ²„νŠΌ (JavaScript둜 κΈ°λŠ₯ λΆ€μ—¬).
    • menu(μ‹€ν—˜μ ): μ—°κ²°λœ 메뉴λ₯Ό μ—½λ‹ˆλ‹€.
  • form (HTML5): <button>을 λͺ…μ‹œμ μœΌλ‘œ 폼(form μš”μ†Œμ˜ id)κ³Ό μ—°κ²°. (λ²„νŠΌμ΄ 폼 λ°”κΉ₯에 μžˆμ–΄λ„ μ—°κ²° κ°€λŠ₯)
  • name: 폼 제좜 μ‹œ μ„œλ²„λ‘œ 전달될 λ²„νŠΌμ˜ 이름.
  • value: 폼 제좜 μ‹œ μ„œλ²„λ‘œ 전달될 λ²„νŠΌμ˜ κ°’.
  • disabled: λ²„νŠΌ λΉ„ν™œμ„±ν™” (클릭 λΆˆκ°€).
  • autofocus (HTML5): νŽ˜μ΄μ§€ λ‘œλ“œ μ‹œ λ²„νŠΌμ— μžλ™ 포컀슀.

 

μ ‘κ·Όμ„± κ³ λ € 사항

  • λͺ…ν™•ν•œ λ ˆμ΄λΈ”: λ²„νŠΌμ˜ λͺ©μ μ„ λ‚˜νƒ€λ‚΄λŠ” ν…μŠ€νŠΈ λ ˆμ΄λΈ” ν•„μˆ˜.
  • ARIA 속성: 슀크린 리더 μ‚¬μš©μžλ₯Ό μœ„ν•΄ aria-label, aria-pressed λ“± μ‚¬μš© κ°€λŠ₯.
  • μ‹œκ°μ  ν‘œν˜„ + ν…μŠ€νŠΈ: 이미지 λ²„νŠΌμ˜ 경우 aria-label λ“±μœΌλ‘œ κΈ°λŠ₯ μ„€λͺ….

 

<a> νƒœκ·Έλ₯Ό λ²„νŠΌμ²˜λŸΌ μ‚¬μš©ν•˜λŠ” κ²ƒμ˜ 문제점

  • <a> νƒœκ·Έμ˜ 본래 의미(링크)λ₯Ό μžƒμŒ.
  • 슀크린 리더 μ‚¬μš©μžμ—κ²Œ ν˜Όλž€ 유발.
  • μ‹œλ§¨ν‹± 웹에 뢀적합: <button> μ‚¬μš© ꢌμž₯. href="#", href="javascript:void(0)"와 ν•¨κ»˜ <a>λ₯Ό μ‚¬μš©ν•˜λŠ” 것은 지양해야함.

 

πŸ“Œ select

<label for="pet-select">Choose a pet:</label>

<select name="pets" id="pet-select">
  <option value="">--Please choose an option--</option>
  <option value="dog">Dog</option>
  <option value="cat">Cat</option>
  <option value="hamster">Hamster</option>
  <option value="parrot">Parrot</option>
  <option value="spider">Spider</option>
  <option value="goldfish">Goldfish</option>
</select>

 

κΈ°λ³Έ μ‚¬μš©λ²•:

  • id 속성을 μ‚¬μš©ν•˜μ—¬ <label>κ³Ό μ—°κ²°ν•˜μ—¬ 접근성을 ν–₯상
  • name 속성을 μ‚¬μš©ν•˜μ—¬ μ„œλ²„λ‘œ 전솑될 λ°μ΄ν„°μ˜ 이름을 μ§€μ •
  • <option> μš”μ†Œλ₯Ό μ€‘μ²©ν•˜μ—¬ 메뉴 μ˜΅μ…˜μ„ μ •μ˜

 

<option> μš”μ†Œ:

  • value 속성은 선택 μ‹œ μ„œλ²„λ‘œ 전솑될 데이터 값을 μ§€μ •
    • value 속성이 μ—†μœΌλ©΄ μš”μ†Œ λ‚΄λΆ€μ˜ ν…μŠ€νŠΈκ°€ κΈ°λ³Έκ°’μœΌλ‘œ μ‚¬μš©
  • selected 속성을 μ‚¬μš©ν•˜μ—¬ νŽ˜μ΄μ§€ λ‘œλ“œ μ‹œ κΈ°λ³Έ 선택 μ˜΅μ…˜μ„ μ§€μ •
    • selected 속성이 μ—†μœΌλ©΄ 첫 번째 <option> μš”μ†Œκ°€ 기본적으둜 선택

 

JavaScript:

  • HTMLSelectElement 객체둜 ν‘œν˜„
  • value 속성은 μ„ νƒλœ <option>의 값을 포함

 

<select> μš”μ†Œμ˜ 속성:

  • multiple: μ—¬λŸ¬ μ˜΅μ…˜ 선택 κ°€λŠ₯ μ—¬λΆ€λ₯Ό μ§€μ •
  • size: ν•œ λ²ˆμ— ν‘œμ‹œν•  μ˜΅μ…˜ 수λ₯Ό μ§€μ •
  • required, disabled, autofocus λ“± 일반적인 폼 μž…λ ₯ 속성도 μ‚¬μš© κ°€λŠ₯

 

μΆ”κ°€ κΈ°λŠ₯:

  • <optgroup> μš”μ†Œλ₯Ό μ‚¬μš©ν•˜μ—¬ μ˜΅μ…˜μ„ κ·Έλ£Ήν™” κ°€λŠ₯
  • <hr> μš”μ†Œλ₯Ό μ‚¬μš©ν•˜μ—¬ μ˜΅μ…˜ 사이에 μ‹œκ°μ  ꡬ뢄선을 μΆ”κ°€ν•  수 있음

 

πŸ“Œ list, datalist

list 속성은 <input> μš”μ†Œμ— μžλ™ μ™„μ„± κΈ°λŠ₯을 μ œκ³΅ν•˜λŠ” <datalist> μš”μ†Œλ₯Ό μ—°κ²°ν•˜λŠ” 데 μ‚¬μš©

 

  • list μ†μ„±μ˜ μ—­ν• :
    • <input> μš”μ†Œμ™€ μ—°κ²°ν•  <datalist> μš”μ†Œμ˜ id 값을 μ§€μ •
    • <datalist> μš”μ†ŒλŠ” <input> μš”μ†Œμ— λŒ€ν•œ 미리 μ •μ˜λœ μ˜΅μ…˜ λͺ©λ‘μ„ μ œκ³΅ν•˜μ—¬ μžλ™ μ™„μ„± κΈ°λŠ₯을 κ΅¬ν˜„

 

  • <datalist> μš”μ†Œμ™€μ˜ 관계:
    • list 속성 값은 λ™μΌν•œ λ¬Έμ„œ 내에 μžˆλŠ” <datalist> μš”μ†Œμ˜ id와 μΌμΉ˜μ‹œμΌœμ•Ό 함
    • <datalist> μš”μ†ŒλŠ” <option> μš”μ†Œλ“€μ„ ν¬ν•¨ν•˜μ—¬ μžλ™ μ™„μ„± μ˜΅μ…˜ λͺ©λ‘μ„ ꡬ성

 

  • list 속성을 μ§€μ›ν•˜λŠ” <input> νƒ€μž…:
    • text, search, url, tel, email, date, month, week, time, datetime-local, number, range, color
    • checkbox, radio, file, buttonκ³Ό 같은 νƒ€μž…μ—μ„œλŠ” list 속성이 λ¬΄μ‹œλ¨.

 

  • μ‚¬μš©μž κ²½ν—˜ (UX):
    • μ‚¬μš©μžκ°€ <input> μš”μ†Œμ— 값을 μž…λ ₯ν•  λ•Œ, <datalist>에 μ •μ˜λœ μ˜΅μ…˜λ“€μ΄ λ“œλ‘­λ‹€μš΄ ν˜•νƒœλ‘œ ν‘œμ‹œλ˜μ–΄ μ„ νƒν•˜κ±°λ‚˜, 직접 μž…λ ₯ν•  수 있음
    • <datalist>λŠ” μ œμ•ˆ λͺ©λ‘μ„ μ œκ³΅ν•˜λŠ” 것이며, <select> μš”μ†Œμ²˜λŸΌ 선택을 κ°•μ œν•˜μ§€ μ•ŠμŒ

 

  • autocomplete μ†μ„±κ³Όμ˜ 관계:
    • list속성을 μ‚¬μš©ν•˜λ©΄ autocomplete속성을 μ‚¬μš©ν•  ν•„μš”κ°€ μ—†μŒ
    • list 속성은 <datalist>λ₯Ό 톡해 μžλ™ μ™„μ„± μ˜΅μ…˜μ„ λͺ…μ‹œμ μœΌλ‘œ μ œκ³΅ν•˜λŠ” 반면, autocomplete 속성은 λΈŒλΌμš°μ €μ˜ 일반적인 μžλ™ μ™„μ„± κΈ°λŠ₯(이전에 μž…λ ₯ν•œ κ°’ 기반)을 μ œμ–΄

 

  • readonly속성, sizeμ†μ„±κ³Όμ˜ ν˜Έν™˜μ„±
    • readonly속성을 μ‚¬μš©ν•˜μ—¬ 읽기 μ „μš©μœΌλ‘œ μ„€μ •ν•œ <input>μ—μ„œλ„ list속성과 μ—°κ²°λœ <datalist>κ°€ λ™μž‘ν•¨.
    • <input>의 sizeμ†μ„±μœΌλ‘œ 크기λ₯Ό μ‘°μ ˆν•΄λ„,list속성과 μ—°κ²°λœ <datalist>κ°€ λ™μž‘ν•¨.
<label for="ice-cream-choice">Choose a flavor:</label>
<input list="ice-cream-flavors" id="ice-cream-choice" name="ice-cream-choice">

<datalist id="ice-cream-flavors">
    <option value="Chocolate">
    <option value="Coconut">
    <option value="Mint">
    <option value="Strawberry">
    <option value="Vanilla">
</datalist>

 

 

datalist

  •  <input> μš”μ†Œμ— λŒ€ν•œ μžλ™ μ™„μ„± μ˜΅μ…˜ 제곡.
  • <input> μš”μ†Œμ˜ list 속성에 <datalist> μš”μ†Œμ˜ idλ₯Ό μ§€μ •ν•˜μ—¬ μ—°κ²°
  • <option> μš”μ†Œ μ‚¬μš©:
    • <datalist> 내뢀에 <option> μš”μ†Œλ₯Ό μ‚¬μš©ν•˜μ—¬ μ˜΅μ…˜λ“€μ„ μ •μ˜
    • value 속성: <input>에 μ‹€μ œλ‘œ μž…λ ₯될 κ°’.
    • label 속성 (선택 사항): μ‚¬μš©μžμ—κ²Œ 보여쀄 μ„€λͺ… (λΈŒλΌμš°μ €μ— 따라 λ‹€λ₯΄κ²Œ ν‘œμ‹œλ  수 있음).
    • <option> μš”μ†Œμ˜ ν…μŠ€νŠΈ λ‚΄μš©λ„ value λŒ€μ‹  μ‚¬μš©λ  수 있음.
  • <select> μš”μ†Œμ™€μ˜ 차이점:
    • <select>: μ‚¬μš©μžκ°€ λ°˜λ“œμ‹œ μ£Όμ–΄μ§„ μ˜΅μ…˜ 쀑 ν•˜λ‚˜λ₯Ό 선택
    • <datalist>: μ‚¬μš©μžλŠ” μ˜΅μ…˜μ„ μ„ νƒν•˜κ±°λ‚˜, 직접 μž…λ ₯ν•  수 있음.
  • μ ‘κ·Όμ„± 고렀사항
    • <datalist>λ₯Ό μ‚¬μš©ν•  λ•Œ 슀크린 리더 μ‚¬μš©μžμ—κ²Œ  <input>에 μžλ™μ™„μ„± κΈ°λŠ₯이 μžˆμŒμ„ μ•Œλ €μ£Όμ–΄μ•Ό 함
    • aria-autocomplete속성을 톡해 μžλ™μ™„μ„± λ™μž‘ 방식을 λͺ…μ‹œν•  수 있음
    • both: λͺ©λ‘κ³Ό 인라인 ν˜•νƒœ λͺ¨λ‘ 제곡
    • inline: ν…μŠ€νŠΈλ₯Ό 타이핑 ν•  λ•Œ μžλ™μ™„μ„±
    • list: λ¦¬μŠ€νŠΈμ—μ„œ 선택
    • none : μžλ™μ™„μ„± λ™μž‘ μ—†μŒ.
  • 속성
    • <datalist>μš”μ†ŒλŠ” μ „μ—­ νŠΉμ„±μ„ 가짐
<label for="myBrowser">Choose a browser from this list:</label>
<input list="browsers" id="myBrowser" name="myBrowser">
<datalist id="browsers">
  <option value="Chrome">
  <option value="Firefox">
  <option value="Internet Explorer">
  <option value="Opera">
  <option value="Safari">
  <option value="Microsoft Edge">
</datalist>

 

πŸ“Œ file

<input type="file" id="filepicker" name="fileList" multiple />
<output id="output"></output>
const output = document.getElementById("output");
const filepicker = document.getElementById("filepicker");

filepicker.addEventListener("change", (event) => {
  const files = event.target.files;
  output.textContent = "";

  for (const file of files) {
    output.textContent += `${file.name}: ${file.type || "μ•Œ 수 μ—†μŒ"}\n`;
  }
});

type 속성을 μœ μΌν•œ μœ νš¨μ„± 검증 μˆ˜λ‹¨μœΌλ‘œ μ‚¬μš©ν•˜λŠ” 건 ꢌμž₯ν•˜μ§€ μ•ŠμŒ

 

πŸ“Œ disabled, readonly

  • disabled -> λ¬΄μš©μ§€λ¬Ό
    •  disabled 속성이 μžˆμ„ 경우 ν•΄λ‹Ή μš”μ†ŒλŠ” μˆ˜μ •ν•˜κ±°λ‚˜ 포컀슀λ₯Ό 맞좜 수 μ—†μŒ.
    • 폼을 톡해 제좜될 μˆ˜λ„ 없읍
    • <button>, <fieldset>, <optgroup>, <option>, <select>, <textarea>, <input> μ—μ„œ 지원
  • readonly -> κ³ μ •κ°’ μœ μ§€

 

  • disabled와 readonly의 μ°¨μ΄λŠ” 읽기 μ „μš©μœΌλ‘œ μ§€μ •λœ μ»¨νŠΈλ‘€μ€ μ—¬μ „νžˆ λ™μž‘ν•˜κ³  ν¬μ»€μŠ€κ°€ κ°€λŠ₯ν•˜λ‹€λŠ” 반면,
  • λΉ„ν™œμ„±ν™”λœ μ»¨νŠΈλ‘€μ€ 포컀슀λ₯Ό λ°›κ±°λ‚˜ 폼과 ν•¨κ»˜ μ œμΆœλ˜μ§€ μ•Šκ³  일반적으둜 ν™œμ„±ν™”λ  λ•ŒκΉŒμ§€ μ»¨νŠΈλ‘€λ‘œμ„œ λ™μž‘ν•˜μ§€ μ•ŠμŒ

 

  • λΉ„ν™œμ„±ν™”λœ ν•„λ“œλŠ” κ·Έ 값이 변경될 수 μ—†κΈ° λ•Œλ¬Έμ—, requiredλŠ” disabled 속성이 μ§€μ •λœ μž…λ ₯ ν•„λ“œμ— 아무 영ν–₯도 λ―ΈμΉ˜μ§€ μ•ŠμŒ
  • μš”μ†Œλ“€μ΄ λ³€κ²½ λΆˆκ°€λŠ₯ν•˜κ²Œ λ˜λ―€λ‘œ pattern κ³Ό 같은 λŒ€λΆ€λΆ„μ˜ λ‹€λ₯Έ 속성듀도 컨트둀이 ν™œμ„±ν™”λ  λ•ŒκΉŒμ§€ 영ν–₯을 λ―ΈμΉ˜μ§€ μ•ŠμŒ

μ°Έκ³ : disabled 속성이 μ§€μ •λœ μž…λ ₯ ν•„λ“œμ—λŠ” required 속성을 μ‚¬μš©ν•  수 μ—†μŠ΅λ‹ˆλ‹€.

 

disabled μœ μš©μ„±

  • λΈŒλΌμš°μ €λŠ” λΉ„ν™œμ„±ν™”λœ 폼 μ»¨νŠΈλ‘€λ“€μ„ νšŒμƒ‰μœΌλ‘œ ν‘œμ‹œ
  • λΉ„ν™œμ„±ν™”λœ 폼 μ»¨νŠΈλ‘€μ€ λ³€κ²½λ˜κ±°λ‚˜ 폼과 ν•¨κ»˜ μ œμΆœλ˜μ§€ μ•ŠμŒ
  • 마우슀 ν΄λ¦­μ΄λ‚˜ ν¬μ»€μŠ€μ™€ κ΄€λ ¨λœ λΈŒλΌμš°μ§• 이벀트λ₯Ό μˆ˜μ‹ ν•˜μ§€ μ•ŠμŒ
  • μ§€μ›ν•˜λŠ” μš”μ†Œμ— μ‘΄μž¬ν•˜λŠ” 경우 :disabled μ˜μ‚¬ ν΄λž˜μŠ€κ°€ 적용
  • ν•΄λ‹Ή 속성이 μ§€μ •λ˜μ§€ μ•Šμ•˜μ„ κ²½μš°μ—λŠ” :enabled μ˜μ‚¬ ν΄λž˜μŠ€κ°€ 적용
  • μš”μ†Œκ°€ λΉ„ν™œμ„±ν™” 속성을 μ§€μ›ν•˜μ§€ μ•ŠλŠ” κ²½μš°μ—λŠ” ν•΄λ‹Ή 속성이 μ–΄λ–€ νš¨κ³Όλ„ κ°–μ§€ μ•ŠμœΌλ©°, :disabled 와 :enabled μ˜μ‚¬ ν΄λž˜μŠ€λ„ μ μš©λ˜μ§€ μ•ŠμŒ

 

readonly

The Boolean readonly attribute, when present, makes the element not mutable, meaning the user can not edit the control.