Skip to content

Event for submitting single-field (onEnterKey/onSubmit perhaps?) #35

@frnco

Description

@frnco

I've been using Mint for a while, and in pretty much every project I ended up having to deal with the same problem. The most common scenario is when creating a Search Box. Seems pretty simple, create a <Ui.Input >, define a state to hold its value (Shouldn't be needed but let's roll with it), define an onChange event that updates the state, and now I have to submit it... onIconClick makes for half of the solution, but a reasonable search box will also trigger when the user hits the Enter key, and that's not so easy in mint.

Right now I'm using this slight aberration to make this work:

onChange={(newValue : String) : Promise(Never,Void) {
  next { fieldValue = newValue }
}}
onKeyDown={(e : Html.Event) : Promise(Never,Void) {
  if (e.key == "Enter") {
    "someUrl/#{`encodeURI(#{fieldValue})`}"
    |> Window.navigate
  } else {
    Promise.never()
    }
}}
onIconClick={(e : Html.Event) : Promise(Never,Void) {
  "someUrl/#{`encodeURI(#{fieldValue})`}"
  |> Window.navigate
}}

The else branch is irrelevant boilerplate, and the e.key == "Enter" doesn't check for modifiers like Ctrl or Shift or pretty much anything. It's be a lot easier to have something like:

onSubmit={(fieldValue : String) : Promise(Never,Void){
  "someUrl/#{`encodeURI(#{fieldValue})`}"
  |> Window.navigate
}}

which could actually replace all three handlers above, with the added benefit of doing away with having a state.

Am I the only one who thinks this is a good idea, or are there others who agree we could use something like this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions