{"id":22706794,"url":"https://github.com/bigbinary/elm-form-field","last_synced_at":"2025-06-17T06:04:48.758Z","repository":{"id":52693408,"uuid":"141738596","full_name":"bigbinary/elm-form-field","owner":"bigbinary","description":"A simple data structure to capture form data","archived":false,"fork":false,"pushed_at":"2021-04-20T20:44:03.000Z","size":18,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-06-09T07:04:11.770Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://package.elm-lang.org/packages/bigbinary/elm-form-field/latest","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bigbinary.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-20T17:13:43.000Z","updated_at":"2019-02-24T03:56:23.000Z","dependencies_parsed_at":"2022-08-22T06:40:12.225Z","dependency_job_id":null,"html_url":"https://github.com/bigbinary/elm-form-field","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/bigbinary/elm-form-field","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Felm-form-field","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Felm-form-field/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Felm-form-field/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Felm-form-field/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigbinary","download_url":"https://codeload.github.com/bigbinary/elm-form-field/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Felm-form-field/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260301994,"owners_count":22988719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-10T10:09:45.179Z","updated_at":"2025-06-17T06:04:48.735Z","avatar_url":"https://github.com/bigbinary.png","language":"Elm","readme":"# Field\n\nA `Field` is a simple data type that helps capture and validate form data better.\nThe left side of a field represents a function that takes in a value of arbitrary type,\nvalidates it and returns a `ValidationResult`.\n\nThe `ValidationResult` can contain the value of the field if the validation `Passed`, or\nan error if the validation `Failed`\n\n## Example\n\nAssume that we have a form with name, email and phone as inputs.\nThen we can define these as `Field`s as follows\n\n```elm\n\nimport Field exposing (..)\nimport Field.ValidationResult exposing (..)\n\ntype alias Model =\n    { name : Field String String\n    , email : Field String String\n    , phone : Field String String\n    }\n```\n\nThe left `String` of a `Field` refers to the error and the right `String` refers to the actual value type\n\nWe can initialize these as follows\n\n```elm\ninit =\n    { name = Field validateEmpty \"\"\n    , email = Field (validateEmpty \u003e\u003e andThen validateEmail) \"\"\n    , phone = Field validateNumbersOnly \"\"\n    }\n```\n\nThe `Field` constructor takes two arguments. The first one is a validation function which takes in value of the field and produces a `ValidationResult` type\n\n```elm\nvalidateEmpty : String -\u003e ValidationResult String String\nvalidateEmpty s =\n    case s of\n        \"\" -\u003e\n            Failed \"Field cannot be empty\"\n\n        _ -\u003e\n            Passed s\n```\n\nValidate a `Field` using the `validate` function.\n\nExample of a `Passed` validation:\n\n```elm\n\nname = Field validateEmpty \"John Doe\"\n\nnameValidationResult = validate name\n\n-- nameValidationResult == Passed \"John Doe\"\n```\nExample of a `Failed` validation:\n\n```elm\n\nemail = Field validateEmpty \"\"\n\nemailValidationResult = validate email\n\n-- emailValidationResult == Failed \"Field cannot be empty\"\n```\n\nRefer [example](https://github.com/bigbinary/elm-form-field/blob/master/examples/Form.elm)\nfor more\n\n\n## Documentation\n\nRefer documentation [here](http://package.elm-lang.org/packages/bigbinary/elm-form-field/latest)\n\n## About BigBinary\n\n![BigBinary](https://raw.githubusercontent.com/bigbinary/bigbinary-assets/press-assets/PNG/logo-light-solid-small.png?raw=true)\n\nelm-reader is maintained by [BigBinary](https://www.BigBinary.com). BigBinary is a software consultancy company. We build web and mobile applications using Ruby on Rails, React.js, React Native and Elm.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigbinary%2Felm-form-field","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigbinary%2Felm-form-field","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigbinary%2Felm-form-field/lists"}