@penta-b/attributes-compare-customfield
v1.3.2
Published
Attributes Compare custom field for Editing Plugin smart forms: compares configured attributes across configured sources and shows Matched/Different statuses live.
Readme
Attributes Compare Custom Field
A Penta-b MNA smart-forms custom field (attributes-compare-customfield) for Editing Plugin forms.
It compares the value of each admin-configured attribute across two or more admin-configured
sources (for example Card, Register, Field Visit), shows a Matched / Different status per
attribute, a compact summary of how many attributes differ, and saves the comparison result
into the form data under the field's mnaKey. Recalculates live as the user edits any
configured source field. Optionally blocks form submission while differences exist.
Designer configuration
| Setting | Type | Meaning |
| --- | --- | --- |
| mnaKey | mnaKey | Key the comparison result is saved under. |
| sources | grid (repeatable rows) | The authoritative sources list: Source id (stable internal id, e.g. card) and Source label (column header). Row order = column order. Minimum two rows. |
| attributeMappings | grid (repeatable rows) | One row per (attribute, source) pair: Attribute (text), Source id (must match a declared source), Field (dropdown listing the form's fields). |
| blockSubmitOnDifference | checkbox | When enabled, submission is blocked while at least one attribute is Different. Default off. |
| classname | text | CSS class name, default penta-r12. |
The Field cell is a dropdown populated with the fields available in the form (any
Wizard/Tabs/Group nesting) — the admin picks a field instead of typing its key. Source
identity and column order come only from the sources grid: a mapping row referencing an
undeclared source id is reported as a configuration error instead of silently creating an
extra column, and renaming a source label never re-keys saved results.
Example:
sources
| Source id | Source label | | --- | --- | | card | Card | | register | Register |
attributeMappings
| Attribute | Source id | Field | | --- | --- | --- | | Crop Type | card | cardCropType | | Crop Type | register | registerCropType | | Irrigation | card | cardIrrigation | | Irrigation | register | registerIrrigation |
A missing or empty value in any source makes the attribute Different. A selected field that no longer exists in the form shows a clear per-cell message (FR-12). If the same field key exists at several locations in the form data, the first match is used and the conflicting paths are logged to the browser console (nothing is shown to the end user).
Saved value shape
values is keyed by the stable source id:
{
"summary": { "total": 3, "differentCount": 2, "hasDifferences": true },
"attributes": [
{ "label": "Crop Type", "status": "DIFFERENT", "values": { "card": "Wheat", "register": "Corn" } }
]
}Installing as an npm package
The package ships the prebuilt UMD bundle (dist/build/attributes-compare-customfield.js) as its
entry point. Importing it registers the field with the smart-forms loader as a side effect:
import "attributes-compare-customfield";react, react-dom, redux, react-redux, @penta-b/ma-lib and
@penta-b/mna-penta-smart-forms are peer dependencies — the host application must provide
them (they are marked as webpack externals and are not bundled).
To test locally without publishing:
npm run build
npm pack # produces attributes-compare-customfield-1.0.0.tgz
npm install ../attributes-compare-customfield-1.0.0.tgz # from the consuming appTo publish (runs the build automatically via prepublishOnly):
npm publishDevelopment
npm run dev— dev server on port 3003 (http://localhost:3003/attributes-compare-customfield.js).npm run prod— UMD bundle todist/build/attributes-compare-customfield.js.npm run storybook— Storybook on port 6006.
