Skip to main content Skip to docs navigation

Save on enter/on change Form Example

On this page
Stats
#callbacks:

Source

scala
import com.fastscala.components.bootstrap5.helpers.BSHelpers.*
val BSFormRenderer = new BSForm7Renderers {
  override def defaultRequiredFieldLabel: String = "Required Field"
}
import BSFormRenderer.*
div.border.p_2.rounded.apply {
  new Form7 with QueryStringSavedForm {

    override def submitOnSuggestion: Boolean = true

    override lazy val rootField: F7Field = F7VerticalField()(
      F7ContainerField("row")("col" -> new F7StringField().label("First Name").id("first_name"), "col" -> new F7StringField().label("Last Name").id("last_name")),
      new F7StringField().label("Email").inputType("email").id("email"),
      new F7StringTextareaField().label("Address").id("address"),
      new F7SelectField[Country](CountriesData.data.toList).label("Country of Residence").option2String(_.name.common).id("country"),
      new F7LocalDateOptField().label("Birthday").id("birthday"),
      new F7CheckboxField().label("Login enabled").id("login_enabled"),
      new F7CheckboxOptField().label("Is veteran?").id("veteran"),
      new F7MultiSelectField[String]().options(List("Sales", "Support", "Development", "Accounting")).label("Security clearance to access:").id("security_clearance"),
      new F7RadioField[String](() => List("Email", "Phone", "SMS")).label("Preferred contact method:").id("contact_method"),
      new F7SubmitButtonField[BSBtn](implicit fsc => BSBtn().sm.addClass(w_100.d_block.getClassAttr), _.lbl("Saved").BtnOutlineSecondary, _.lbl("Save").BtnSuccess, _.lbl("Error").BtnDanger)
    )

    override def formRenderer: F7FormRenderer = BSFormRenderer.formRenderer
  }.render()
}