Retrieve kintone form field(@kintone/rest-api-client) information in a pretty format.
Provides the field information needed to create a kintone plugin.
-
Get both field and spacer.
Check Kintone Developer Program for property details. -
Obtain in layout order. (top left first, bottom right after)
-
Determine the fields in a table.
Set the table field code to the table property.
{
type: 'SINGLE_LINE_TEXT',
code: '文字列__1行_',
label: '文字列 (1行)',
noLabel: false,
required: false,
minLength: '',
maxLength: '',
expression: '',
hideExpression: false,
unique: false,
defaultValue: '',
table: 'テーブル' // table field code
}
- Determine the fields in a group.
Set the group field code to the group property.
{
type: 'SINGLE_LINE_TEXT',
code: '文字列__1行_',
label: '文字列 (1行)',
noLabel: false,
required: false,
minLength: '',
maxLength: '',
expression: '',
hideExpression: false,
unique: false,
defaultValue: '',
group: 'グループ' // group field code
}
- Determine the destination field for copying lookups.
Set the true to the isLookupCopy property.(Requires lookup source app permissions)
{
type: 'SINGLE_LINE_TEXT',
code: '文字列__1行_',
label: '文字列 (1行)',
noLabel: false,
required: false,
minLength: '',
maxLength: '',
expression: '',
hideExpression: false,
unique: false,
defaultValue: '',
isLookupCopy: true // If true, lookup copy destination field
}
- Sorts the values of the options.
{
type: 'CHECK_BOX',
code: 'チェックボックス',
label: 'チェックボックス',
noLabel: false,
required: false,
options: {
sample1: { label: 'sample1', index: '0' },
sample4: { label: 'sample4', index: '3' },
sample3: { label: 'sample3', index: '2' },
sample2: { label: 'sample2', index: '1' }
},
defaultValue: [],
align: 'HORIZONTAL',
sortedOptions: [ 'sample1', 'sample2', 'sample3', 'sample4' ] // sorted options
}
This library is distributed on npm
.
npm install kintone-pretty-fields
You can then use import
to import the library.
// ES modules
import { kintonePrettyFields } from "kintone-pretty-fields";
Here is a sample code that retrieves form fields of an app.
import { KintoneRestAPIClient } from "@kintone/rest-api-client";
import { kintonePrettyFields, kintonePrettyType } from "kintone-pretty-fields";
const client = new KintoneRestAPIClient();
const { fields, spacers } = await kintonePrettyFields.get({ client, app: 1, lang: "en", preview: false });
console.log({ fields, spacers });
const checkBoxFields = fields.filter(kintonePrettyFields.isCheckBox);
console.log(checkBoxFields);
const inSubtableFields = fields.filter(kintonePrettyFields.isInSubtable);
console.log(inSubtableFields);
const myFunction1 = (fields: kintonePrettyType.OneOf[]) => {
// do something
};
const myFunction2 = (field: kintonePrettyType.CheckBox) => {
// do something
};