If you really want to get down to inner working of things here is a general summary.
Each form element can be thought of as object since that is what it is server-side. Properties for that object will have a direct impact on how styling needs to be applied. Take for instance a text field. There are several types of text fields such as; email, url, etc. So data-fapi-widget is used so that a form element can be selected by widget type. Though specific to text types they are also flagged as data-fapi-textfield because at this point in time they are being styled the same. This means all that needs to be done to select all textfield is target form elements with an attribute data-fapi-textfield as possed to creating a list with the different types such as; data-fapi-widget=text,data-fapi-widget=email, data-fapi-widget=url, etc. There are many types of widgets provided by the form API textfield is merely the simplest. Also, some types need to expose additional information regarding state for styling reasons. How this is all accomplished is via using a wrapping div with data attributes that follow the pattern data-fapi-{propname} (for booleans) and data-fapi-{propname}=val for all other values.
Now I know the traditional meaning of form element is the form control such as; the input itself for a textfield. However, in the form API context it is that form control and any other information related to it such as; label, description text and error string(s). Wrapping those elements with a division provides a consistent means of selecting errors, descriptions, labels, etc for a form element. Simply use “data-fapi-widget=email .description”. As opposed to applying more classes to the supportive information for a form element or relying on element location using some form of sibling selectors. Granted I know that no descriptions or error strings exist in my example they are part of the form API and need to be handled appropriately in combination fir the controls themselves. Wrapping all associated information to the control like that of error strings displayed next to control and descriptions provides that mechanism in easy, reusable, consistent form for styling and js manipulation if need be.
The data-fapi-form flag exist to turn on the generic styling. Though this has not been done in the CSS yet all generic form api styles will eventually start off with form[data-fapi-form] … Thus when a form does not use require generic styles be applied the attribute can simply be omitted. So it pretty much will act as a flag for turning on and off generic form API styles and/or identifying forms managed by the server-side form API library.
The fapi prefix is the name of the library that manages the forms. I am simply trying to reduce the possibility of name collisions. Also provide a means of easily seeing which attributes belong to the form api itself. If I were to removed it my attributes would end up being something like data-widget=“” which could very well conflict with the name of an attribute for something else in the future. To prevent that fapi is prefixed to each property.
What I hope to accomplish with this is having 90% of all form CSS being taken care of by generic styles supplied by the form library. As opposed to none which results in the needless repetition of similar presentation code across different applications that use the form API to build/manage forms of all kinds ie. data entry, search, registration, email, etc.
The thing you have to understand in all this is that forms are being dynamically generated based on a configuration file and callback functions server-side when need be. Up to this point I have handled all the CSS manually on an application by application basis. After creating several sites using the form library I have come to the realization that it would be best to handle a portion of the CSS to both reduce repetition, provide centralized debug/change point and improve my efficiency when developing new sites/applications. I don’t think a few extra attributes and wrappers compares to all the things that will gained by doing this.
Initial I though it did which is why when I went in to add this functionality I made it a configuration option. So you can actually see the same exact form without just about all wrappers here. Though now I have come to a different realization having worked on many sites I have. So yeah…