fulcrologic / fulcro-rad

Fulcro Rapid Application Development
MIT License
201 stars 46 forks source link

Validations of subform attributes #118

Open danskarda opened 1 year ago

danskarda commented 1 year ago

When adding validation to subform's attributes I found strange behaviors:

The validations are simple ao/required? true defined on attribute level. Form subform relation is ao/cardinality :many

As I investigated the issue and tried to narrow down a reproducible example

Replicate in recent fulcro-rad-demo@5e40e59 (Datomic version)

  1. open the app
  2. Invoices > View All
  3. Select any invoice
  4. Add a Line Item
  5. Set quantity
  6. Click save

image

As you can see Line item was saved without an Item.

Interestingly, when you reopen the same item invoice, the missing value is marked as required image

Are you able to reproduce same behavior with fulcro-rad-demo?

Some idea:

The :event/save handler uses result of fs/completed-form-props to feed validate function:

https://github.com/fulcrologic/fulcro-rad/blob/9a8176203c948956fce2ccfc577ca167a5ff6182/src/main/com/fulcrologic/rad/form.cljc#L1292

                                master-pk           (::attr/qualified-key id)
                                proposed-form-props (fs/completed-form-props state-map form-class form-ident)
                            if (valid? form-class proposed-form-props)

After some poor's man debugging using js/console I found that proposed-form-props does not include new items. To be honest I have no clue why or what these functions are doing.

Thanks

awkay commented 1 week ago

Sorry, I've not had time to look at this. I'm heavily using forms in RAD, and my guess is this is an oversight in the demo implementation. Forms must have explicit validators to do validation correctly, and when there are refs, you may also need to ensure that the edges are validated. My guess is that this particular case just wasn't coded fully.