item-editing v2.22.2
Item Editing
The package responsible for generating UI to edit Items.
The home of form-gen, the home of FieldEditors, etc..
Item Form
Forms are generated from nestable JSON coniguration. As with all of items, the configs are completely serializable and contain no in memory functions. All behavior must somehow be described by static configuration.
Form Elements
Common Form Properties
All form elements can contain the following optional properties:
Property | Type | Function |
---|---|---|
styles? | string[] | Most commonly used. An array of classnames (currently) that can be used to style form elements according to our standardized global CSS style helpers. At some point we will need to narrow the set of styles available to a semantically named set but for iteration speed currently all are available. |
ruleConditions? | Array | Analagous to item-action's executeRuleConditions. All the rule conditions in the array must be true for the element (and all of it's children) to display. This also affects it's initActions described below. Interpolation may be used in all ruleConditions of the form elements and behaves the same way as in actions. |
loadingRuleConditions? | Array | Similar to ruleConditions but will display a loader instead of the UI when true. Still affects initActions etc. |
initActions? | IItemAction[] | An array of actions to fire when the element is first loaded. Generally, for initiating asynchronous UI but may be used for clearing state or anything else the heart desires. These will not fire until all the parent ruleCondtions are true and loadingRuleConditions are false. |
dataDts? | string | a custome data-dts attribute to override form-gen's generic default for use in automated tests. |
Field Element
Field elements are the primary element of forms. They essentially create an editor to edit a particular field value.
Property | Type | Function |
---|---|---|
field | IField | The only required property. Tells form gen which field this will be responsible for editing. |
changeActions? | IItemAction[] | An array of actions to fire whenever the field value of this field is changed by the field editor. May be used to cause side effects from a field change such as loading a set of list options based on a previous list option selection (aka models based on makes etc). |
labelElement? | IItemFormElement | Itself a formElement, a custom label override for those few cases where you need more than just text in the label of your editor. Generally, otherwise the field.name property is used. |
optional? | boolean or Array | All fields in form gen are given an extra validation {required : true} before being passed to the editor (which is currently responsible for validation) because the assumption is that it wouldn't be in the form if you didn't want to require it. This flag let's you override that behavior and not require the field. |
override? | IItem | An item of type FIELD_OVERRIDE used to provide a custom (aka not fetched from the DB) override of this field's behavior. See field override's in the item package for more info. |
inlineItemOpts? | see below | an object configuring the behavior of this element when it's field is type ITEM . Special enough and important enough to deserve it's own section below. |
Inline Item Field Element
Configured by the inlineItemOpts property of a field element. When no configuration is specified, the UI will simple be a list of all items stored on the field value with a delete button on each and an add button to add new. For each item, all the fields of that type are added in a row as editors.
Property | Type | Function |
---|---|---|
enableAddRemove? | boolean or Array | True when no config is provided, but otherwise defaults to false. Decides whether the delete and add buttons are added to whatever UI is rendered for the items whether that is custom or default. |
enableAdd? | boolean or Array | True when no config is provided, but otherwise defaults to false. Decides whether the add buttons are included in whatever UI is rendered for the items whether that is custom or default. |
addText? | string | Custom text label for add link when enableAdd or enabledAddRemove is true |
enableRemove? | boolean or Array | True when no config is provided, but otherwise defaults to false. Decides whether the delete buttons are included in whatever UI is rendered for the items whether that is custom or default. |
formConfig? | IItemFormConfig | A form config to render for each item within the field values of the ITEM field. In the form prep stage a duplicate config will be generated scoped to each item in the array. Within interpolations this item may be referenced with CURRENT_ITEM instead of the standard ITEM ref. Any normal elements may be used here. They will be rendered for each and every item. Field elements are scoped to the inline item being rendered. |
partialFormConfig? | IItemFormConfig | A formConfig partial that should shallow merge with the default formConfig (e.g. adding custom ruleConditions while using the default formElements ) |
Copy Element
Renders text. A copy element may also be represented as just a plain string for convenience. The object form allows access to base element properties such as style.
Property | Type | Function |
---|---|---|
copy | string | the text to render, when interpolations are found in the string they are replaced with the formatted field value (this is true of all text interpolations in form elements). |
Submit Element
Says submit, but may be used for any button style element. Interpolations may be used within text.
Property | Type | Function |
---|---|---|
submitActions | IItemAction[] | The actions to fire on click. |
text? | string | Text to rener in the button instead of the default 'Continue' |
Hyper Link Element
Renders a standard hyperlink with non dynamic behavior (aka only href not javascript). Both href and text may contain interpolations.
Property | Type | Function |
---|---|---|
href | string | Maps directly to the <a href="... property |
text | string | The rendered text of the link |
target? | string | Maps directly to the <a target="... property, generally for use with "_blank" to open links in a new window / tab |
Image Element
Renders an img. Currently no interpolations allowed but this is likely a bug.
Property | Type | Function |
---|---|---|
src | string | Maps directly to the <img src="... property |
Custom Field Element
Renders custom fields (fields not known and named in code).
Property | Type | Function |
---|---|---|
customFields | string, IField[] | If a string, assumed to be an interpolation pointing to a field value that contains Items of type CUSTOM_FIELD, these items will be transformed into an array fields during the prep phase. After prep the customFields element just renders a field form element for each of it's fields, currently without any config or customization. |
Mechanics and Life Cycle
Item forms are rendered in specific stages, partially to help with reentry and validation outside of component rendering. The config based to item form is first run the the prepareElementTree
function, which recursively evaluates the conditions of the elements against the rootItem and extraCtx (just as in item actions) and a fieldMap (which is passed in order to allow non-code and customField definitions). If the condition for an element doesn't pass it simply isn't returned in the prepped tree. If it does, all interpolations in it's text properties are replaced against the context and any sub-elements or configs (label element, form config, inlineItemOpts.formConfig) are prepared recursively exactly the same way. The result of this phase is a prepped element tree of type IItemPreppedFormElement[]
. There are prepped versions of all the element types, because the prepped elements have numerious things replaced or removed before ever rendering.
The form components then somewhat dumbly render the prepped tree (also recursively but simply using components). Whenever, a component renders a prepped element it fires its initActions
up the tree (this should eventually be handled outside of the component tree but isn't for now). If it finds in img element it renders an img tag, a submit element renders a button etc. On any change to the properties or state of the form (including field value changes from the rendered editors) the tree is re-prepped and simply rendered again (this is highly efficient because of react's shadow dom and diffing).
When a field element is found, if it is of type ITEM a special <InlineItemFieldFormElement>
component is rendered. This component takes care of automatically capturing field value edits from the child field editors within it, writing them into the particular inline item being rendered, and then bubbling the change to that item into the ITEM field's field value up the tree. It also can handle removing an item from or adding an item to the array of inline item field values.
Field Editors
The code responsible for editing the value of one particular field on an item using it's type and options to decide the behavior.
A field editor takes in a field along with a field value and handles rendering the appropriate editor for that field, taking into account any editorType or editorOptions. Editor options and their function are documented in to the item package.
It fires any field value change through an onChange
callback. It handles validating the user entered field values and rendering invalid states as danger color borders etc. If a value is valid synchronously (according to the field's validations
property), it submits any field value changes to an asyncValidation callback. If the validity value has changed from false to true or vice versa it fires an onValidatyChange callback to alert parent components.
Field editors use the item package's field-processor code to format
and render the field values to user readable strings, and to parse
user entered strings into raw fieldvalues for saving (when the ui is text based unlike a date select for example). They also run all validations through the field processor. This allows the meat and bones of that logic to be UI agnostic and highly testable, while the editor handles any UI specific concerns for the field. Again see the item package for how field types are treated in regard to format, parse, and validations.
Random Stuff to Later Organize
- all field ids are aggregated from the config and attempted to be fetched before rendering by checkout. currently assumes only the application item and wierd
CHECKOUT
fields but that must soon change.
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago