V8FormsAPI - kwantu/platformconfiguration GitHub Wiki

V8FormsAPI

This API will enable external form system to interact with the V8 platform.

With the initial understanding of the system config generated knockout+wijmo forms interact with the system with fixed inline function calls and invokes relevant functions to fetch, validate and save data.

With this new API we can use separate independent JSON forms that now can interact with the V8 platform. Our approach would be

JSON Form (LLM generated) -> JSONFormRenderer -> FormRuntimeAPI -> Existing app.js / services / workflows (System Libraries)

Documentation

Overview

The FormRuntimeAPI a interface for managing forms, including initialization, validation, saving, taxonomy loading, and file attachments (duplicate check not included here)

Constructor

new FormRuntimeAPI(options)

Parameters:

  • options (Object, optional)
    • app (Object) - Application instance (default: window.app)
    • service (Object) - Service instance (default: window.service)
    • library (Object) - Library instance (default: window.library)
new FormRuntimeAPI()
Loads
 app = window.app,
 service = window.service,
 library = window.library

Example:

const formAPI = new FormRuntimeAPI({
  app: myAppInstance,
  service: myServiceInstance,
  library: myLibraryInstance
});

Form Initialization

initializeForm(formJson, context)

Initializes a form with default values and loads existing data if available.

Parameters:

  • formJson (Object) - The form configuration/schema
  • context (Object, optional) - Context object
    • atomId (String) - ID of existing form data to load

Returns: Promise<Object> - The initialized form model

Example:

const model = await formAPI.initializeForm(formJson, { atomId: '123' });

loadDefaultModel(context)

Loads the default model for a form.

Parameters:

  • context (Object, optional) - Context object

Returns: Promise<Object> - Default model object

loadExistingModel(context)

Loads an existing model from storage.

Parameters:

  • context (Object, optional) - Context object

Returns: Promise<Object> - Existing model object


Taxonomy Management

loadTaxonomy(taxonomyId, context)

Loads taxonomy data and caches it for future use.

Parameters:

  • taxonomyId (String) - Unique identifier for the taxonomy
  • context (Object, optional) - Context object

Returns: Promise<Array> - Taxonomy data array

Example:

const categories = await formAPI.loadTaxonomy('categories', { profileId: '456' });

getTaxonomy(taxonomyId)

Retrieves cached taxonomy data synchronously.

Parameters:

  • taxonomyId (String) - Unique identifier for the taxonomy

Returns: Array - Cached taxonomy data (empty array if not loaded)

Example:

const categories = formAPI.getTaxonomy('categories');

Search

loadSearch(searchId, params, context)

Performs a search and caches results based on search ID and parameters.

Parameters:

  • searchId (String) - Unique identifier for the search
  • params (Object, optional) - Search parameters
  • context (Object, optional) - Context object

Returns: Promise<Array> - Search results array

Example:

const results = await formAPI.loadSearch('userSearch', { query: 'john' }, { profileId: '456' });

Validation

validateForm(model, formJson, context)

Validates the form model against required fields and custom validation rules.

Parameters:

  • model (Object) - Current form model/data
  • formJson (Object) - Form configuration/schema
  • context (Object, optional)
    • profileId (String) - Profile ID for validation

Returns: Promise<Object> - Validation result

  • valid (Boolean) - Whether the form is valid
  • errors (Object) - Map of field IDs to error messages

Example:

const { valid, errors } = await formAPI.validateForm(model, formJson, { profileId: '456' });
if (!valid) {
  console.log('Validation errors:', errors);
}

Save Operations

saveForm(model, context)

Saves the form data.

Parameters:

  • model (Object) - Form model/data to save
  • context (Object, optional)
    • formJson (Object) - Form configuration (required for onSave rules)

Returns: Promise<any> - Result from app.save() or null

Example:

await formAPI.saveForm(model, { formJson });

saveDraft(model, context)

Saves the form as a draft.

Parameters:

  • model (Object) - Form model/data to save as draft
  • context (Object, optional) - Context object

Returns: Promise<any> - Result from app.saveAsDraft() or null

Example:

await formAPI.saveDraft(model);

closeForm()

Closes the current form.

Returns: void

Example:

formAPI.closeForm();

Attachments

uploadAttachment(file, context)

Uploads a file attachment.

Parameters:

  • file (File) - File object to upload
  • context (Object, optional) - Additional context for upload

Returns: Promise<any> - Upload result or null

Example:

const result = await formAPI.uploadAttachment(fileObject, { fieldId: 'document' });

openAttachmentLibrary(context)

Opens the attachment library for file selection.

Parameters:

  • context (Object, optional) - Context object

Returns: any - Result from app.libUpload() or null

Example:

formAPI.openAttachmentLibrary({ fieldId: 'attachments' });

Rules Engine

runRules(event, formJson, model, context)

Executes rules configured for a specific event.

Parameters:

  • event (String) - Event name ('onLoad', 'onSave', etc.)
  • formJson (Object) - Form configuration containing rules
  • model (Object) - Current form model
  • context (Object) - Context object

Returns: Promise<void>

Supported Events:

  • onLoad - Triggered when form is initialized
  • onSave - Triggered before form is saved

Example:

await formAPI.runRules('onLoad', formJson, model, context);

updateTitle(model, context, rule)

Updates the form/page title based on a field value.

Parameters:

  • model (Object) - Current form model
  • context (Object) - Context object
  • rule (Object) - Rule configuration
    • updates[0].source (String) - Field path (e.g., '/fieldName')

Returns: void


Internal Methods

_loadTaxonomyFile(id, params, context)

Internal method to load taxonomy files from the library.

Parameters:

  • id (String) - Taxonomy file ID
  • params (Object, optional) - Query parameters
  • context (Object, optional) - Context object

Returns: Promise<Array> - Taxonomy data

_flattenFields(formJson)

Internal utility to flatten form fields from sections.

Parameters:

  • formJson (Object) - Form configuration

Returns: Array - Flattened array of field objects


Caching

The API implements internal caching for performance:

  • Taxonomy Cache: taxonomyCache - Stores loaded taxonomies by ID
  • Search Cache: searchCache - Stores search results by ID and parameters

Cached data is reused for subsequent requests with the same identifiers.


Dependencies

The API requires the following external objects:

  • window.app - Application interface with methods: save(), saveAsDraft(), closeForm(), fileUpload(), libUpload()
  • window.service - Service interface with method: validateForm()
  • window.library - Library interface with methods: get_taxonomy_file(), eval()

⚠️ **GitHub.com Fallback** ⚠️