Skip to content

liveview-native/liveview-native-live-form

Repository files navigation

LiveForm for LiveView Native

liveview-native-live-form is an add-on library for LiveView Native. It adds support for HTML-style forms on native platforms.

Installation

Elixir

If available in Hex, the package can be installed by adding live_view_native_live_form to your list of dependencies in mix.exs:

def deps do
  [
    {:live_view_native_live_form, "~> 0.3.0"}
  ]
end

SwiftUI

  1. In Xcode, select File → Add Packages...
  2. Enter the package URL https://github.com/liveview-native/liveview-native-live-form
  3. Select Add Package

Usage

Import LiveViewNativeLiveForm and add .liveForm to the list of addons on your LiveView:

import SwiftUI
import LiveViewNative
import LiveViewNativeLiveForm

struct ContentView: View {
    var body: some View {
        #LiveView(
            .localhost,
            addons: [.liveForm]
        )
    }
}

Now you can use the LiveForm and LiveSubmitButton elements in your template.

<LiveForm
  id="my-form"
  phx-change="form-changed"
  phx-submit="submit"
>
  <TextField name="username">Username</TextField>
  <SecureField name="password">Password</SecureField>
  <LiveSubmitButton>Submit</LiveSubmitButton>
</LiveForm>