reach4thelasers
reach4thelasers

Reputation: 26899

Angular Schema Forms: Master Schema

I'm writing a financial application form. Angular Schema Forms is perfect for the kind of flexibility I need to make the forms.

I'm having a bit of trouble getting my head around the concept of a schema, in particular: should a schema relate to a single form, or all the forms in an app?

I have many types of Financial Products that a user can apply for.... Checking Account, Savings Account, Car Insurance, House, Pet, Gadget Insurance. Many of the fields in the various forms are common to all: Name, Date of Birth, Address. Some are specific to one form or a couple of forms (Car Registration Number).

Should I have one all-encompassing schema which contains definitions for all of the possible fields in all of my forms, and add/override them in the Form definition object? Or should each form contain its own Schema? Or even each page in each form?

And if its either of the latter two - how do I prevent duplication? DRY!

Upvotes: 3

Views: 179

Answers (1)

Anthropic
Anthropic

Reputation: 701

The Schema vs the UI Schema The way I think of it is that the Schema represents a view of your data model and the UI Schema represents an editable version of the view. Can you write a view that includes all of your fields in the database, yes, but I'm more likely to look at the specifics of what data I need.

In my projects I generate a JSON Schema for each product/service I provide customers and I used the json-refs library to allow me to pre-process json schema references ($ref) so that I can re-use definitions.

In my case I have an order schema which includes only order related data, customer address, order related dates, etc... that every order will need. I also have a product schema for each product. I then include the order and product into a combined schema with $ref. Each product can have multiple sections and attributes which I also re-use across products.

Now in your case it would seem like my solution would fit as our data is similar, however I do not know what your back end library is. That said the new alpha versions of Angular Schema Form support $ref using json-ref on the client side, but I would still look for a back end solution if your stack has a supporting library or you are using NodeJS and can use json-ref.

Upvotes: 2

Related Questions