Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validations of subform attributes #118

Open
danskarda opened this issue Aug 22, 2023 · 1 comment
Open

Validations of subform attributes #118

danskarda opened this issue Aug 22, 2023 · 1 comment

Comments

@danskarda
Copy link
Contributor

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

  • I was able to save forms with invalid subforms (fulcro-rad-demo)
  • After clicking Save nothing happened, because backend db enforced the constrain. Front-end validation passed and it did nor warned that save have not succeeded (sql backend enforced constrains)
  • When multiple fields were invalid only some of them were marked as invalid. After fixing these fields, previously unreported invalid fields become highlighted
  • Validations on subforms were triggered only when some toplevel attribute become invalid

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

  • the issue is not caused by compilation, caches and schadow-cljs reload (defattrs are in .cljc files)
  • the issue is not caused by custom UISM nor validator
  • the issue persists with much simpler form (Account with two 1:n subforms User and Credential, both subforms with required fields)
  • finally I was able to replicate the issue (or similar) with fulcro-rad-demo

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:

(if (valid? form-class proposed-form-props)

                                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
Copy link
Member

awkay commented Oct 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants