Expand my Community achievements bar.

Best way to apply Schemas to Fragments

Avatar

Level 2

I'm been researching the best way to apply schemas to my fragments.   Either by applying all fragment and field schema elements to the form

or to put the fragment schema elements within the fragment.   I feel keeping a schema within the fragment seems like the way to go, but

unsure.   I you only reference a fragments schema in a form and a fragment within that form changes, do you have to go back a modify every form schema that is using that fragment?  If I keep the schema in the fragment then I would only need to modify the fragment schema..correct?

Wow..hope this makes sense.

2 Replies

Avatar

Former Community Member

It is recommended to use relative binding in a fragment and not absolute binding. To do this bind the root node of the fragment to the appropriate node in the schema. Then bind all fields on the form relative to the root node. This technique allows you to reuse the fragment in any schema that uses that structure. Now when you reference the frgament in the main form you have to bind the root node of the fragment (the subform) to the proper node in the schema. All fields on the form are relative to this node and can reolve their bindings relative to the subform container binding.

Hope that helps

Paul

Avatar

Former Community Member

I agree with the small caveat that it sort of depends on the business/technical requirements surrounding your use of fragments.  Fragments can be sort of flaky and difficult to work with so to peg a specific all-encompassing "best practice" would, in my opinion, be impossible.  Using relative bindings in fragments is great (in fact it's what I'm doing on my current LC project), but it ends up becoming a bit limiting.  It can make the fragment pretty tightly coupled to the "main" XDP form and whatever schema/XML is bound to it.  Probably 9 times out of 10, that's not an issue, but the reasons for electing to use fragments can make it something you really need to think about.

My advice would be to avoid fragments unless you specifically need that functionality for a specific reason.  It's easy to use fragments because they are cool and seem clean, but then can end up causing more headache than it's worth.  On the other hand, using fragments as a method of compartmentalizing script objects is really really helpful.  It helps you keep all your JavaScript inside script objects (instead of inside object events) and allows for reuse of scripts in different areas of the form(s).  This saves development time, refactoring time, and disk space.  I highly recommend looking into that scenario whenever possible.

Hope this helps.

Ryan D. Lunka

Cardinal Solutions Group

rlunka@cardinalsolutions.com