for more information visit the package's GitHub page
Package contains the following modules:
Generate validating forms from JSON schemas.
elm package install scrive/json-schema-form
text
, select
, etc.) with optional labels and descriptions.$ref
.See the example project for examples of all the supported field types.
module Main exposing (main)
import Browser
import Dict
import Html exposing (..)
import Html.Events exposing (onSubmit)
import Json.Schema
import Json.Schema.Form exposing (Msg, State)
main : Program () State Msg
main =
Browser.sandbox { init = init, update = update, view = view }
schema =
"""
{
"type": "object",
"required": ["name"],
"properties": {
"name": {
"type": "string",
"title": "Name"
}
}
}
"""
init : State
init =
case Json.Schema.fromString schema of
Ok schema_ ->
Json.Schema.Form.init
{ errors = \path error -> "Invalid field: " ++ path
, formats = Dict.empty
}
schema_
Err error ->
Debug.todo error
update : Msg -> State -> State
update msg state =
Json.Schema.Form.update msg state
view : State -> Html Msg
view state =
form [ onSubmit Json.Schema.Form.submit ]
[ Json.Schema.Form.view state
, button [] [ text "Submit" ]
]