Giter VIP home page Giter VIP logo

Comments (6)

ThijsWouters avatar ThijsWouters commented on June 19, 2024

No, that did not fix it. I added a test to describe the behaviour I am after. Correct me if I am wrong:

  • Look in the changes,
  • if nothing is there, look in the params,
  • if nothing is there, look in the data,
  • if nothing is there, return the default value or nil.

I'll see if I can make the changes.

from phoenix_ecto.

ThijsWouters avatar ThijsWouters commented on June 19, 2024

I can't fix it in this repo. This behaviour needs a change in phoenixframework/phoenix_html.

The precedence now is: params -> default -> changes -> data.

This feels wrong, especially that the default value is taken before the changes or actual data.

I think the precedence should be: changes -> params -> data -> default.

from phoenix_ecto.

josevalim avatar josevalim commented on June 19, 2024

@ThijsWouters can you please check Ecto master?

You are correct except by the default which should have higher preference than the data because the default often uses a value computed on top of the data.

from phoenix_ecto.

ThijsWouters avatar ThijsWouters commented on June 19, 2024

@josevalim Taking the default over the data does not make sense to me.

Let's say we have a transaction with a date. We want a default date of today.

So you say that when we start to edit the transaction, the date field is not filled with the previously chosen date, but with the current date?

from phoenix_ecto.

josevalim avatar josevalim commented on June 19, 2024

The default is used for cases where you want to use a value that was computed on top of the data value, hence you want it to have higher precedence:

input_value(form, :name, String.upcase(data.name))

If you really want a value if nothing else was set then you can do this:

input_value(form, :name) || "fallback"

Maybe it is a matter of giving it a better name than default, such as "computed".

Changing it would also be backwards incompatible, so finding a better way to describe is the best way to go.

Did the rest work as expected on master?

from phoenix_ecto.

ThijsWouters avatar ThijsWouters commented on June 19, 2024

It does work as expected on master, thanks.

default is indeed a confusing name for something like this.

from phoenix_ecto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.