<commit_before>package io.youi.form

import org.scalajs.dom.{Event, html}

class FormInput(formSupport: FormSupport, val element: html.Element) {
  val error: FieldError = formSupport.createFieldError(this)

  element.addEventListener("blur", (_: Event) => {
    validate(ValidationMode.Blur)
  })
  element.addEventListener("change", (_: Event) => {
    validate(ValidationMode.ValueChange)
  })

  def name: String = element match {
    case i: html.Input => i.name
    case i: html.TextArea => i.name
    case i: html.Select => i.name
    case _ => throw new RuntimeException(s"Unsupported getting name in FormInput for: ${element.innerHTML}")
  }

  def focus(): Unit = element.focus()

  def option: Option[String] = value match {
    case s if s != null && s.trim.nonEmpty => Some(s)
    case _ => None
  }

  def value: String = element match {<commit_msg>Added FormInput.select() support<commit_after>package io.youi.form

import org.scalajs.dom.{Event, html}

class FormInput(formSupport: FormSupport, val element: html.Element) {
  val error: FieldError = formSupport.createFieldError(this)

  element.addEventListener("blur", (_: Event) => {
    validate(ValidationMode.Blur)
  })
  element.addEventListener("change", (_: Event) => {
    validate(ValidationMode.ValueChange)
  })

  def name: String = element match {
    case i: html.Input => i.name
    case i: html.TextArea => i.name
    case i: html.Select => i.name
    case _ => throw new RuntimeException(s"Unsupported getting name in FormInput for: ${element.innerHTML}")
  }

  def focus(): Unit = element.focus()

  def select(): Unit = element match {
    case i: html.Input => i.select()
    case i: html.TextArea => i.select()
    case _ => throw new RuntimeException(s"Unsupported select() in FormInput for: ${element.innerHTML}")
  }

  def option: Option[String] = value match {
    case s if s != null && s.trim.nonEmpty => Some(s)
    case _ => None
  }

  def value: String = element match {
{'fraction_non_alphanumeric': 0.13292744799594114, 'fraction_numerical': 0.0, 'mean_word_length': 3.7290167865707433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2643273', 'n_tokens_mistral': 608, 'n_tokens_neox': 600, 'n_words': 166}