Skip to content

createForm

Factory that encapsulates useForm, useFormValidation, useRecordFields, useSObject, useSuspense and useDML

Import

import { createForm } from 'c/bolt';

Usage

import fields from './fields.js';
import template from './myLwc.html';
export default class myLwc extends createForm(
{fields, template},
args
) { }

Methods

constructor(params, configurationArgs) : Constructor

NameTypeDescription
{fields}Field[] OR Field[][]Array of imported fields
{template}FunctionImported HTML template
{untilTemplate}FunctionImported HTML template
{mode}edit OR insertMode of the form
argsCreateFormConfArgsTo add traits to the class

Example

Basic
import { createForm } from 'c/bolt';
import template from './myLwc.html';
import fields from './caseFields.js';
export default class MyLwc extends createForm( { fields, template } ) {
@api recordId;
async handleSave() {
if(this.formValidity)
await this.saveRecord(this.Case);
}
}
<template>
<c-bolt-input lwc:spread={$Case.Subject}></c-bolt-input>
<c-bolt-input lwc:spread={$Case.Status}></c-bolt-input>
<c-bolt-input lwc:spread={$Case.Priority}></c-bolt-input>
<c-bolt-input lwc:spread={$Case.Contact}></c-bolt-input>
<lightning-button label="Save the record" onclick={handleSave}></lightning-button>
</template>
With other traits
import { createForm } from 'c/bolt';
import template from './myLwc.html';
import fields from './caseFields.js';
export default class MyLwc extends createForm(
{ fields, template },
{
externalStyles: `p {color: red;}`,
poller: {
resolveCondition: [prop => prop === 'OK', 'status__c'],
wiredMethod: 'apexResults',
maxIteration: 10,
interval: 1000
}
}
) {
@api recordId;
async handleSave() {
if(this.formValidity)
await this.saveRecord(this.Case);
}
}
<template>
<c-bolt-input lwc:spread={$Case.Subject}></c-bolt-input>
<c-bolt-input lwc:spread={$Case.Status}></c-bolt-input>
<c-bolt-input lwc:spread={$Case.Priority}></c-bolt-input>
<c-bolt-input lwc:spread={$Case.Contact}></c-bolt-input>
<lightning-button label="Save the record" onclick={handleSave}></lightning-button>
</template>