メインコンテンツまでスキップ

フィールド定義を取得(同期)

概要

atPocket.app.fields は、表示中のフォームのフィールド定義を同期的に取得します。
イベントオブジェクトからのフィールド定義の提供は終了したため、フィールド定義が必要な場合はこの関数を使用してください。

一覧画面・ポータル画面では使用できません。これらの画面では フィールド定義を取得(非同期) を使用してください。

構文

atPocket.app.fields.get(fieldUid);
atPocket.app.fields.getAll();

引数

引数名説明
fieldUidstring取得したいフィールドのUID。明細(SubTable)の列UIDも指定できます

戻り値

関数説明
get(fieldUid)object | null指定したフィールドの定義。存在しない場合は null
getAll()objectフィールドUIDをキーにした定義のマップ
getAll() に含まれる範囲

getAll() が返すマップのキーはフォームに直接配置されたフィールドのUIDのみです。明細(SubTable)の列は、明細フィールドの定義の columns の中に入ります(マップの直下には現れません)。
列UIDから定義を引く場合は get(列UID) を使用してください。

フィールド定義の内容

プロパティ説明
fieldUidstringフィールドUID(例: "field-2"
typestringフィールドタイプ(連携フィールドは "RelationSelect"
labelstring表示ラベル
requiredboolean必須項目かどうか
editableboolean編集可能かどうか
isMultiboolean複数選択かどうか
optionsarray選択肢({ value, label } の配列)。単一選択・ラジオボタン・チェックボックス等
defaultValueany初期値
relationboolean連携フィールドかどうか
columnsobject明細(SubTable)の列定義(列UID をキーにしたマップ)
parentSubTableUidstring明細の列の場合、属する明細フィールドのUID
備考

フィールド定義には、設計時の情報のみが含まれます。実行時に setFieldShown などで変更した表示状態は含まれません。

使用可能画面

  • レコード詳細画面
  • レコード作成画面
  • レコード編集画面

使用例

変更されたフィールドのUIDから定義を引く

atPocket.events.on('app.record.edit.change', (event) => {
const def = atPocket.app.fields.get(event.changes.name);
console.log(`${def.label} が変更されました`);
return event;
});

選択肢の一覧を取得する

const def = atPocket.app.fields.get('field-5');
def.options.forEach((option) => {
console.log(option.value, option.label);
});

明細の列の定義を取得する

// 明細フィールドから列をたどる
const subtable = atPocket.app.fields.get('field-6');
Object.values(subtable.columns).forEach((column) => {
console.log(column.fieldUid, column.label);
});

// 列UIDを直接指定する
const column = atPocket.app.fields.get('field-6_1');
console.log(column.parentSubTableUid); // "field-6"

必須項目をすべて取得する

// getAll() はフォームに直接配置されたフィールドのみを返します(明細の列は columns の中)
const map = atPocket.app.fields.getAll();
const required = Object.values(map).filter((def) => def.required);

関連ページ