Document Management
duplicate(original, [defaults])
Creates a deep-cloned and properly formatted duplicate of a Template or Document. Generates a new_id, updates the identifier based on type (template_ or doc_),
resets timestamps, and merges in optional default overrides.
Ensures all references to the original object are removed via deep clone.
Returns: Object - A new object representing the duplicated Template or Document with updated metadata.
| Param | Type | Default | Description |
|---|---|---|---|
| original | Object | The original Template or Document object to duplicate. | |
| [defaults] | Object | {} | Optional default values to override or extend the duplicated object. |
- Creates a deep copy of the original object
- Generates a new ObjectId and identifier
- Adds a fresh
createdOntimestamp - Stores the original identifier under
source - Merges any provided
defaults(e.g., new name)
duplicatePage(doc, fileId, pageId, useReadableIds)
Duplicates a page within a document and generates corresponding changelog entries. This function creates a copy of a specified page in a document and generates changelog entries to track the duplication operation. It handles both primary pages and view pages, as well as any associated fields that need to be created. Returns:Object - An object containing:
{Object} doc- The updated document with the duplicated page{Array} changelogs- Array of changelog entries tracking the duplication
| Param | Type | Description |
|---|---|---|
| doc | Object | The document object containing the page to duplicate |
| fileId | string | The ID of the file containing the document |
| pageId | string | The ID of the page to duplicate |
| useReadableIds | boolean | Whether to use readable IDs for generated elements |
getDefaultPage([defaults])
Creates a default page object for JoyDoc documents. Returns:Object - Default page object with _id, name, width, height, rowHeight, cols, fieldPositions, layout, presentation, and padding
| Param | Type | Default | Description |
|---|---|---|---|
| [defaults] | Object | {} | Optional configuration to override default values |
getDefaultDocument()
Creates a new JoyDoc document with standard properties and structure. The document will have a unique ID, proper type, and identifier. Returns:Object - returns a properly formatted Document JoyDoc
Example
getDefaultTemplate()
Gets a default template structure for JoyDoc documents. Creates a new template object that can be used to generate multiple documents with consistent structure. Templates include predefined layouts, field configurations, and styling options. Returns:Object - returns a properly formatted Template JoyDoc
Example
getDocumentFromTemplate(template)
Get a properly formatted Document JoyDoc from Template JoyDoc Creates a new document by cloning a template and assigning it a unique ID and identifier. The template is deep cloned to remove all references to the original template object. The resulting document maintains the template’s structure (name, files, fields) while being marked as a document type with references to the source template. Returns:Object - A new document with unique _id, identifier, and template references
| Param | Type | Description |
|---|---|---|
| template | Object | The template JoyDoc to create document from |
Conditional Logic
applyLogic(items, fields, [fieldLookupKey])
Applies conditional logic to show/hide items based on field values. Logic object structure:action:'show'or'hide''show': if conditions are met, item becomes visible (hidden = false)'hide': if conditions are met, item becomes hidden (hidden = true)
eval:'and'or'or''and': all conditions must evaluate true'or': at least one condition must evaluate true
conditions: array of rule objects with:field: lookup key of the dependent fieldcondition: operator (see below)value: value to compare against
*=→ Filled (value exists or array non-empty)null=→ Empty (null, empty string, or empty array)=→ Equals (case-insensitive for strings; exact match for numbers)!=→ Not equals?=→ Contains substring (case-insensitive)>→ Greater than (numbers only)<→ Less than (numbers only)
- For each item with a
logicdefinition:- Retrieve referenced fields using
fieldLookupKey - Evaluate all conditions using their operator and
value - Combine results with
eval(and/or) - Apply
actionto update thehiddenproperty accordingly
- Retrieve referenced fields using
- Return updated
itemsarray
Object - Updated fields array (with hidden set to true or false based on the logic)
| Param | Type | Default | Description |
|---|---|---|---|
| items | Array<object> | Array of items (fields, pages, or groups) that may include a logic object. | |
| fields | Array<object> | Array of field objects used for logic evaluation. | |
| [fieldLookupKey] | string | '_id' | Property name used to match conditions to field identifiers. |
conditional_one) was hidden by default but became visible.
Both its conditions evaluated true (field_one contains “hello” and field_two > 50).
Since action: 'show' and all conditions passed with eval: 'and', it became visible.
The second item (conditional_two) was visible by default but became hidden.
Its condition matched because field_three includes “option_one”.
Since action: 'hide' and the or condition passed, it was set to hidden.
Validation
validator(doc, [options])
Validates a JoyDoc document against field rules and constraints. Performs comprehensive validation of a JoyDoc document including field validation rules, required fields, data types, and business logic constraints. Returns:Object - Validation result with status and field validations
| Param | Type | Description |
|---|---|---|
| doc | Object | The JoyDoc document to validate |
| [options] | Object | Validation options |
| [options.view] | string | View type for validation (‘desktop’, ‘mobile’, ‘tablet’) |
validateSchema(doc)
Validates a JoyDoc document against the schema definition. Performs schema validation to ensure the document structure conforms to the JoyDoc schema. Checks for required properties, data types, and structural integrity. Returns:Object | undefined - Returns an error object if validation fails, otherwise undefined.
If an error object is returned, it contains:
{string} [error.code]- Error code (e.g., ‘ERROR_SCHEMA_VALIDATION’){string} [error.message]- Human-readable error message{Array} [error.errors]- Array of detailed validation errors{Object} [error.details]- Additional error details including schema version
| Param | Type | Description |
|---|---|---|
| doc | Object | The JoyDoc document to validate against schema |
Utilities
generateObjectId()
Generates a unique object ID for JoyDoc elements. Creates a unique identifier string that can be used for documents, pages, fields, and other elements in the JoyDoc system. IDs are guaranteed to be unique. Returns:string - A unique object ID string (24-character hex string)
Example
Configuration Objects
fieldOptions
Default field options configuration for the draggable field list. Contains predefined field types, icons, and configurations that can be used in the JoyDoc component to provide a standard set of available field types. You can customize the draggable field options by providing your own fieldOptions array with pre-configured styles, settings, and any other property supported by the JoyDoc Spec. When users drag and drop pre-configured fields, they will have the properties pre-set. Properties| Name | Type | Description |
|---|---|---|
| fieldOptions[].title | string | Display title for the field type |
| fieldOptions[].type | string | Field type identifier (e.g., ‘text’, ‘number’, ‘date’, ‘fieldGroup’) |
| [fieldOptions[].icon] | string | Icon name for the field type |
| [fieldOptions[].iconType] | string | Icon type: ‘custom’ for SVG, ‘url’ for image URL |
| [fieldOptions[].icon] | string | ReactElement | Custom icon (SVG element or image URL) |
| [fieldOptions[].displayType] | string | Display type (e.g., ‘original’, ‘check’) |
| [fieldOptions[].identifier] | string | Custom identifier for the field |
| [fieldOptions[].config] | Object | Default configuration for the field type |
| [fieldOptions[].fields] | Array | Nested fields for fieldGroup type |
| [fieldOptions[].open] | boolean | Whether fieldGroup is open by default |
fieldColumnTypes
Field table column types configuration. Defines available column types for table fields in JoyDoc forms. These constants can be used when creating or configuring table columns to ensure consistency and proper type handling. Properties| Name | Type | Description |
|---|---|---|
| text | string | Text column type identifier |
| dropdown | string | Dropdown column type identifier |
| image | string | Image column type identifier |
| number | string | Number column type identifier |
| multiSelect | string | Multi-select column type identifier |
| date | string | Date column type identifier |
| block | string | Block column type identifier |
| barcode | string | Barcode column type identifier |
| signature | string | Signature column type identifier |
Summary
The Joyfill Web SDK provides a comprehensive set of utility functions for:- Document Management: Create, duplicate, and transform documents and templates
- Conditional Logic: Apply show/hide logic based on field values
- Validation: Validate documents against rules and schemas
- Utilities: Generate IDs and configure field options