# Class Field

Field Class

#### Implements

- AbstractField

- Defined in packages/saltcorn-data/models/field.ts:69

##### Index

### Constructors

constructor

### Properties

attributes
calculated
class
default?
description?
disabled
exclude_from_mobile?
expression?
fieldview?
fieldviewObj?
help?
hidden
id?
in_auto_save?
input_type
is_fkey
is_unique
label
name
options?
parent_field?
postText?
preset_options?
primary_key
refname
reftable?
reftable_name?
reftype?
required
showIf?
sourceURL?
stored
sublabel?
tab?
table?
table_id?
type?
typename?
validator

### Accessors

form_name
isRepeat
listKey
multipartFormData
on_delete_sql
presets
pretty_type
sql_bare_type
sql_type
toBuilder
toJson
type_name

### Methods

add_unique_constraint
alter_sql_type
delete
distinct_values
enable_fkey_constraint
fill_fkey_options
fill_table
generate
remove_unique_constraint
set_calc_joinfields
showIfEnabled
toggle_not_null
update
validate
create
find
findCached
findOne
getTypeAttributes
labelToName
nameToLabel
select_options_query

## Constructors

### constructor

- new Field(o: Field | FieldCfg): Field

  Constructor

  #### Parameters

  - o: Field | FieldCfg

  #### Returns Field

  - Defined in packages/saltcorn-data/models/field.ts:116

## Properties

### attributes

attributes: GenObj

Implementation of AbstractField.attributes

- Defined in packages/saltcorn-data/models/field.ts:102

### calculated

calculated: boolean

- Defined in packages/saltcorn-data/models/field.ts:90

### class

class: string

- Defined in packages/saltcorn-data/models/field.ts:77

### `Optional` default

default?: string

- Defined in packages/saltcorn-data/models/field.ts:79

### `Optional` description

description?: string

- Defined in packages/saltcorn-data/models/field.ts:81

### disabled

disabled: boolean

- Defined in packages/saltcorn-data/models/field.ts:89

### `Optional` exclude_from_mobile

exclude_from_mobile?: boolean

- Defined in packages/saltcorn-data/models/field.ts:106

### `Optional` expression

expression?: string

- Defined in packages/saltcorn-data/models/field.ts:93

### `Optional` fieldview

fieldview?: string

Implementation of AbstractField.fieldview

- Defined in packages/saltcorn-data/models/field.ts:72

### `Optional` fieldviewObj

fieldviewObj?: FieldView

- Defined in packages/saltcorn-data/models/field.ts:107

### `Optional` help

help?: { context?: Row; dynContext?: string[]; topic: string }

- Defined in packages/saltcorn-data/models/field.ts:84

### hidden

hidden: boolean

- Defined in packages/saltcorn-data/models/field.ts:88

### `Optional` id

id?: number

Implementation of AbstractField.id

- Defined in packages/saltcorn-data/models/field.ts:78

### `Optional` in_auto_save

in_auto_save?: boolean

- Defined in packages/saltcorn-data/models/field.ts:105

### input_type

input_type: InputType

Implementation of AbstractField.input_type

- Defined in packages/saltcorn-data/models/field.ts:96

### is_fkey

is_fkey: boolean

Implementation of AbstractField.is_fkey

- Defined in packages/saltcorn-data/models/field.ts:95

### is_unique

is_unique: boolean

- Defined in packages/saltcorn-data/models/field.ts:87

### label

label: string

Implementation of AbstractField.label

- Defined in packages/saltcorn-data/models/field.ts:70

### name

name: string

Implementation of AbstractField.name

- Defined in packages/saltcorn-data/models/field.ts:71

### `Optional` options

options?: any

- Defined in packages/saltcorn-data/models/field.ts:85

### `Optional` parent_field

parent_field?: string

- Defined in packages/saltcorn-data/models/field.ts:75

### `Optional` postText

postText?: string

- Defined in packages/saltcorn-data/models/field.ts:76

### `Optional` preset_options

preset_options?: string[]

- Defined in packages/saltcorn-data/models/field.ts:108

### primary_key

primary_key: boolean

Implementation of AbstractField.primary_key

- Defined in packages/saltcorn-data/models/field.ts:91

### refname

refname: string = ""

- Defined in packages/saltcorn-data/models/field.ts:100

### `Optional` reftable

reftable?: Table

- Defined in packages/saltcorn-data/models/field.ts:101

### `Optional` reftable_name

reftable_name?: string

Implementation of AbstractField.reftable_name

- Defined in packages/saltcorn-data/models/field.ts:97

### `Optional` reftype

reftype?: string | Type

- Defined in packages/saltcorn-data/models/field.ts:99

### required

required: boolean

Implementation of AbstractField.required

- Defined in packages/saltcorn-data/models/field.ts:86

### `Optional` showIf

showIf?: { [field_name: string]: string | boolean | string[] }

- Defined in packages/saltcorn-data/models/field.ts:74

### `Optional` sourceURL

sourceURL?: string

Implementation of AbstractField.sourceURL

- Defined in packages/saltcorn-data/models/field.ts:94

### stored

stored: boolean

- Defined in packages/saltcorn-data/models/field.ts:92

### `Optional` sublabel

sublabel?: string

- Defined in packages/saltcorn-data/models/field.ts:80

### `Optional` tab

tab?: string

- Defined in packages/saltcorn-data/models/field.ts:98

### `Optional` table

table?: Table | null

- Defined in packages/saltcorn-data/models/field.ts:104

### `Optional` table_id

table_id?: number

- Defined in packages/saltcorn-data/models/field.ts:103

### `Optional` type

type?: string | Type

- Defined in packages/saltcorn-data/models/field.ts:82

### `Optional` typename

typename?: string

- Defined in packages/saltcorn-data/models/field.ts:83

### validator

validator: (
value: any,
whole_rec?: Row,
field?: { required: boolean },
) => string | boolean | undefined

- Defined in packages/saltcorn-data/models/field.ts:73

## Accessors

### form_name

- get form_name(): string

  ???

  #### Returns string

  Implementation of AbstractField.form_name

  - Defined in packages/saltcorn-data/models/field.ts:276

### isRepeat

- get isRepeat(): boolean

  #### Returns boolean

  - Defined in packages/saltcorn-data/models/field.ts:196

### listKey

- get listKey(): any

  #### Returns any

  - Defined in packages/saltcorn-data/models/field.ts:1149

### multipartFormData

- get multipartFormData(): boolean

  #### Returns boolean

  - Defined in packages/saltcorn-data/models/field.ts:726

### on_delete_sql

- get on_delete_sql(): string

  #### Returns string

  - Defined in packages/saltcorn-data/models/field.ts:597

### presets

- get presets(): | { LoggedIn: (__namedParameters: { user: any }) => boolean }
  | null

  #### Returns { LoggedIn: (__namedParameters: { user: any }) => boolean } | null

  - Defined in packages/saltcorn-data/models/field.ts:1161

### pretty_type

- get pretty_type(): string

  #### Returns string

  Implementation of AbstractField.pretty_type

  - Defined in packages/saltcorn-data/models/field.ts:660

### sql_bare_type

- get sql_bare_type(): string

  #### Returns string

  - Defined in packages/saltcorn-data/models/field.ts:670

### sql_type

- get sql_type(): string

  #### Returns string

  - Defined in packages/saltcorn-data/models/field.ts:609

### toBuilder

- get toBuilder(): any

  To Json

  #### Returns any

  - Defined in packages/saltcorn-data/models/field.ts:231

### toJson

- get toJson(): any

  To Json

  #### Returns any

  - Defined in packages/saltcorn-data/models/field.ts:204

### type_name

- get type_name(): string | undefined

  #### Returns string | undefined

  Implementation of AbstractField.type_name

  - Defined in packages/saltcorn-data/models/field.ts:266

## Methods

### add_unique_constraint

- add_unique_constraint(): Promise<void>

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/field.ts:832

### alter_sql_type

- alter_sql_type(new_field: Field): Promise<void>

  #### Parameters

  - new_field: Field

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/field.ts:874

### delete

- delete(): Promise<void>

  #### Returns Promise<void>

  #### Throws

  - Defined in packages/saltcorn-data/models/field.ts:1175

### distinct_values

- distinct_values(
  req?: any,
  where?: Where,
  only_present?: boolean,
  ): Promise<{ jsvalue?: boolean; label: string; value: string }[]>

  Distinct Values

  #### Parameters

  - `Optional` req: any
  - `Optional` where: Where
  - `Optional` only_present: boolean

  #### Returns Promise<{ jsvalue?: boolean; label: string; value: string }[]>

  - Defined in packages/saltcorn-data/models/field.ts:507

### enable_fkey_constraint

- enable_fkey_constraint(table: Table): Promise<void>

  #### Parameters

  - table: Table

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/field.ts:1213

### fill_fkey_options

- fill_fkey_options(
  force_allow_none?: boolean,
  where0?: Where,
  extraCtx?: any,
  optionsQuery?: any,
  formFieldNames?: string[],
  existingValue?: any,
  user?: any,
  ): Promise<void>

  Fills 'this.options' with values available via foreign key Could be used for <options /> in a
  to select a user

  #### Parameters

  - `Optional` force_allow_none: boolean = false
  - `Optional` where0: Where
  - extraCtx: any = {}
  - `Optional` optionsQuery: any

    remote/local query to load rows from 'reftable_name'

  - `Optional` formFieldNames: string[]
  - `Optional` existingValue: any
  - `Optional` user: any

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/field.ts:327

### fill_table

- fill_table(): void

  #### Returns void

  - Defined in packages/saltcorn-data/models/field.ts:982

### generate

- generate(): Promise<any>

  #### Returns Promise<any>

  - Defined in packages/saltcorn-data/models/field.ts:697

### remove_unique_constraint

- remove_unique_constraint(): Promise<void>

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/field.ts:840

### set_calc_joinfields

- set_calc_joinfields(): Promise<void>

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/field.ts:991

### showIfEnabled

- showIfEnabled(whole_rec: any): boolean

  #### Parameters

  - whole_rec: any

  #### Returns boolean

  - Defined in packages/saltcorn-data/models/field.ts:716

### toggle_not_null

- toggle_not_null(not_null: boolean): Promise<void>

  #### Parameters

  - not_null: boolean

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/field.ts:854

### update

- update(v: Partial<Field> | Partial<FieldCfg>): Promise<void>

  #### Parameters

  - v: Partial<Field> | Partial<FieldCfg>

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/field.ts:1061

### validate

- validate(whole_rec: any): {} | ResultMessage

  #### Parameters

  - whole_rec: any

  #### Returns {} | ResultMessage

  - Defined in packages/saltcorn-data/models/field.ts:735

### `Static` create

- create(fld: Field | FieldCfg, bare?: boolean, id?: string): Promise<Field>

  #### Parameters

  - fld: Field | FieldCfg
  - bare: boolean = false
  - `Optional` id: string

    optional id, if set, no '_sc_fields' entry is inserted

  #### Returns Promise<Field>

  - Defined in packages/saltcorn-data/models/field.ts:1241

### `Static` find

- find(where?: Where, selectopts?: SelectOptions): Promise<Field[]>

  #### Parameters

  - `Optional` where: Where
  - `Optional` selectopts: SelectOptions = ...

  #### Returns Promise<Field[]>

  - Defined in packages/saltcorn-data/models/field.ts:792

### `Static` findCached

- findCached(where?: Where): Field[]

  #### Parameters

  - `Optional` where: Where

  #### Returns Field[]

  - Defined in packages/saltcorn-data/models/field.ts:813

### `Static` findOne

- findOne(where: Where): Promise<Field>

  #### Parameters

  - where: Where

  #### Returns Promise<Field>

  - Defined in packages/saltcorn-data/models/field.ts:824

### `Static` getTypeAttributes

- getTypeAttributes(typeattribs?: any, table_id?: number): any

  #### Parameters

  - `Optional` typeattribs: any
  - `Optional` table_id: number

  #### Returns any

  - Defined in packages/saltcorn-data/models/field.ts:1357

### `Static` labelToName

- labelToName(label: string): string

  Label 2 Name

  #### Parameters

  - label: string

  #### Returns string

  - Defined in packages/saltcorn-data/models/field.ts:258

### `Static` nameToLabel

- nameToLabel(label: string): string

  #### Parameters

  - label: string

  #### Returns string

  - Defined in packages/saltcorn-data/models/field.ts:262

### `Static` select_options_query

- select_options_query(
  table_name: string,
  where: Where,
  attributes: any,
  extra_joinfields?: any,
  user?: any,
  ): Promise<any>

  #### Parameters

  - table_name: string
  - where: Where
  - attributes: any
  - extra_joinfields: any = {}
  - `Optional` user: any

  #### Returns Promise<any>

  - Defined in packages/saltcorn-data/models/field.ts:281