alfredfriedrich
Hello,
first time playing around with Ash and hitting a wall. I’m trying to use a calucate in a form field. Lets say I have an attribute :duration, :integer and an attribute :duration_unit, :duration_name in a resource, and a calculate :duration_option, expr(duration <> " " <> duration_unit).
If I try to use the duration_option in a form field, I’m only getting a generic error from AshPhoenix.Form.submit.
I’ve looked at the custom composable types, but I’m using AshSqlite and it does not support this.
I guess “I’m using it wrong”, could someone point me at the “Ash” direction, please? ![]()
Thanks alfred
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sevenseacat
Without knowing what your form looks like or what error you’re seeing, its hard to know what your issue might be! Can you share those, as well as what you’re trying to do?
ken-kost
Okay, so the expression might be the issue:
Also, I’m confused about using
duration_optionin a form field; don’t you mean the form should support entry of attributes that are used in calculation, not the calculation it self.?alfredfriedrich
Thank you for your reply, excuse my brevity, my resource looks like this:
and in my LiveView I create the form:
The error is, that duration and duration_unit are required fields.
I’m trying to use a select field with two database/resource attributes and want to populate the attributes from one virtual field.
In the pre-Ash era, I would’ve parsed the returned form value and written the result to the changeset (direction to db) or joined it for the form field value (direction from db).
The Composite Type in Ash looks exactly like that, but unfortunately AshSqlite does not seem to support those.
I guess
calculationsare only for the direction from db case?alfredfriedrich
I want to create a virtual form field (select) which populates, and is populated from two resource attributes, I hope my other answer to
sevenseacatmake my use case clearer to understand.ken-kost
I understand now.
So if you put in the form the required fields and send them to submit the error would be resolved. Then you could get that submitted entry and load the calculation.
But from what I gather you want the other way. You could parse
datainto params that have required field.zachdaniel
Calculations are likely not the fit here. You are likely looking for arguments. In your create action:
alfredfriedrich
Thank you, if I understand this correct, I’d have to call the
:createaction with the value ofduraction_optionfrom the form as an argument?Regarding
:reading from the database, would that also work witharguments?Feel free to let this problem rest for a while, I understand I need to read more (and more…, and the book too)
Thanks for all the responses.
zachdaniel
You can use arguments on reading yes. it is also possible that you want the calculation for display still. The main thing is that nothing will “reverse engineer” the underlying attributes by virtue of trying to change the calculation. You’ll need arguments for that.
alfredfriedrich
I’ll ponder over that.
alfredfriedrich
I read a little more in the Ash Framework book and in chapter 2 they use the
transform_paramsoption to theform_to_create_resourcecall, so I tried it like this:This works for me as expected, as I understand it, if I’d use
argumentandchangeit would work on theAsh.Changeset, but as far as my example goes, working on the params directly is good for me.I used the
calculationtoo for the<select>form field value by the way.Thanks again, this was fun playing around with
I will definitely use this on my next project.