Skip to content

useForm

Import

import { mix, useForm BoltElement } from 'c/bolt';

Usage

export default class myLwc extends mix(
[useForm, fields, mode],
BoltElement
) { }

Methods

Constructor(fields, mode = ‘edit’) : Constructor

NameTypeDescription
fieldsField[] or Field[][]List of imported fields
modeedit OR insertUse a form in edit record mode or create record mode. Defaults to edit

Example

export default class myLwc extends mix(
[useForm, fields],
BoltElement
) { }

Dynamic attributes

$<ObjectApiName> : FormRecordRef

Supportive Fields

In some cases, you may want to import fields but not necessarily map them to an HTML input. To do just that, you want to use the supportive fields feature of createForm and useForm. Fields passed to the supportiveFields parameter won’t be reflected on the dynamic class property this.$<ObjectApiName> intended to be used like so for example <c-bolt-form record={$Case} />.

import { createForm } from 'c/bolt';
import template from './myLwc.html';
import {fields} from './caseFields.js';
import {supportiveFields} from './caseFields.js';
export default class MyLwc extends createForm( { fields, supportiveFields, template } ) {
@api recordId;
async handleSave() {
if(this.formValidity && this.Case.someSupportiveField__c === 'OK')
await this.saveRecord(this.Case);
}
}