Skip to content

Commit

Permalink
Support Ash forms (#136)
Browse files Browse the repository at this point in the history
* Support Ash forms

* Test Ash form

* Remove some files from build

* 0.6.0
  • Loading branch information
ArthurClemens authored Oct 8, 2023
1 parent 716d3fc commit 5479dec
Show file tree
Hide file tree
Showing 14 changed files with 432 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.6.0

Added support for forms created with [Ash Framework](https://www.ash-hq.org/). See [test/frameworks/ash/form_test.exs](https://github.com/ArthurClemens/primer_live/tree/development/test/frameworks/ash/form_test.exs) for an example.

## 0.5.4

Fixed a bug where the required marker would always be displayed, regardless of the field's required state.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ All PrimerLive components accept the <code>class</code> attribute for customisat
PrimerLive components can be used in <a href="https://github.com/phoenixframework/phoenix_live_view" target="_blank">Phoenix LiveView pages</a> and regular (non-LiveView) views in Phoenix applications.
</p>

<p>
Forms created with <a href"https://www.ash-hq.org/">Ash Framework</a> are supported.
</p>

## Documentation

- [Documentation at Hexdocs](https://hexdocs.pm/primer_live/)
Expand Down
4 changes: 2 additions & 2 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "primer-live",
"version": "0.5.4",
"version": "0.6.0",
"description": "JavaScript and CSS for PrimerLive",
"license": "MIT",
"repository": {},
Expand Down
2 changes: 1 addition & 1 deletion doc-extra/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Add PrimerLive as a dependency in your Phoenix application's `mix.exs`

```
{:primer_live, "~> 0.5"}
{:primer_live, "~> 0.6"}
```

Run `mix.deps get`
Expand Down
26 changes: 25 additions & 1 deletion lib/helpers/attribute_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,33 @@ defmodule PrimerLive.Helpers.AttributeHelpers do
iex> PrimerLive.Helpers.AttributeHelpers.input_name(:profile, :first_name, is_multiple: true)
"profile[first_name][]"
iex> PrimerLive.Helpers.AttributeHelpers.input_name(%Phoenix.HTML.Form{
...> name: :profile,
...> source: %Ecto.Changeset{
...> action: :update,
...> changes: %{first_name: "annette"},
...> errors: [],
...> data: nil,
...> valid?: true
...> }
...> }, :first_name)
"profile[first_name]"
iex> PrimerLive.Helpers.AttributeHelpers.input_name(%PrimerLive.Helpers.TestForm{
...> source: %PrimerLive.Helpers.TestForm{
...> name: "test",
...> source: %Phoenix.HTML.Form{
...> name: :profile,
...> }
...> }
...> }, :first_name)
"first_name"
"""

def input_name(form, field, opts \\ []) do
def input_name(form_or_name, field, opts \\ [])

def input_name(form, field, opts) do
_input_name(form, field, opts[:name], !!opts[:is_multiple])
end

Expand Down
Loading

0 comments on commit 5479dec

Please sign in to comment.