使用JSON結構描述製作最適化表單模型,需要基本了解JSON結構描述。 建議在本文之前閱讀下列內容。
Adobe Experience Manager表單支援使用現有的JSON結構描述作為表單模型來建立最適化表單。 此JSON結構表示組織中後端系統產生或使用資料的結構。 您使用的JSON結構應符合 v4規格.
使用JSON結構描述的主要功能為:
JSON結構包含簡單且複雜的元素類型。 元素具有將規則新增至元素的屬性。 將這些元素和屬性拖曳至適用性表單時,會自動對應至對應的適用性表單元件。
此JSON元素與適用性表單元件的對應如下:
"birthDate": {
"type": "string",
"format": "date",
"pattern": "date{DD MMMM, YYYY}",
"aem:affKeyword": [
"DOB",
"Date of Birth"
],
"description": "Date of birth in DD MMMM, YYYY",
"aem:afProperties": {
"displayPictureClause": "date{DD MMMM, YYYY}",
"displayPatternType": "date{DD MMMM, YYYY}",
"validationPatternType": "date{DD MMMM, YYYY}",
"validatePictureClause": "date{DD MMMM, YYYY}",
"validatePictureClauseMessage": "Date must be in DD MMMM, YYYY format."
}
JSON元素、屬性或屬性 | 適用性表單元件 |
---|---|
具有enum和enumNames約束的字串屬性。 語法,
|
下拉元件:
|
具有格式約束的字串屬性。 例如,電子郵件和日期。 語法,
|
|
|
文字欄位 |
數字屬性 |
子類型設定為float的數值欄位 |
整數屬性 |
子類型設為整數的數值欄位 |
布林屬性 |
切換 |
物件屬性 |
面板 |
陣列屬性 | 最小值和最大值分別等於minItems和maxItems的可重複面板。 僅支援同質陣列。 因此,項約束必須是對象而不是陣列。 |
適用性表單使用JSON結構描述中的可用資訊來對應每個產生的欄位。 特別是:
title
屬性可作為適用性表單元件的標籤。description
屬性設為適用性表單元件的詳細說明。default
屬性可作為「適用性表單」欄位的初始值。maxLength
屬性設為 maxlength
屬性。minimum
, maximum
, exclusiveMinimum
,和 exclusiveMaximum
屬性用於數值框元件。DatePicker component
其他JSON結構屬性 minDate
和 maxDate
已提供……minItems
和 maxItems
屬性可用來限制可從面板元件新增或移除的項目/欄位數。readOnly
屬性設定 readonly
屬性。required
屬性會將「適用性表單」欄位標示為必填欄位,但在面板中(其中type為object),最終提交的JSON資料中的欄位會包含與該物件對應的空白值。pattern
屬性在適用性表單中設為驗證模式(規則運算式)。以下是JSON結構描述的範例。
{
"$schema": "https://json-schema.org/draft-04/schema#",
"definitions": {
"employee": {
"type": "object",
"properties": {
"userName": {
"type": "string"
},
"dateOfBirth": {
"type": "string",
"format": "date"
},
"email": {
"type": "string",
"format": "email"
},
"language": {
"type": "string"
},
"personalDetails": {
"$ref": "#/definitions/personalDetails"
},
"projectDetails": {
"$ref": "#/definitions/projectDetails"
}
},
"required": [
"userName",
"dateOfBirth",
"language"
]
},
"personalDetails": {
"type": "object",
"properties": {
"GeneralDetails": {
"$ref": "#/definitions/GeneralDetails"
},
"Family": {
"$ref": "#/definitions/Family"
},
"Income": {
"$ref": "#/definitions/Income"
}
}
},
"projectDetails": {
"type": "array",
"items": {
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "number"
},
"projects": {
"$ref": "#/definitions/projects"
}
}
},
"minItems": 1,
"maxItems": 4
},
"projects": {
"type": "array",
"items": {
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "number"
},
"projectsAdditional": {
"$ref": "#/definitions/projectsAdditional"
}
}
},
"minItems": 1,
"maxItems": 4
},
"projectsAdditional": {
"type": "array",
"items": {
"properties": {
"Additional_name": {
"type": "string"
},
"Additional_areacode": {
"type": "number"
}
}
},
"minItems": 1,
"maxItems": 4
},
"GeneralDetails": {
"type": "object",
"properties": {
"age": {
"type": "number"
},
"married": {
"type": "boolean"
},
"phone": {
"type": "number",
"aem:afProperties": {
"sling:resourceType": "/libs/fd/af/components/guidetelephone",
"guideNodeClass": "guideTelephone"
}
},
"address": {
"type": "string"
}
}
},
"Family": {
"type": "object",
"properties": {
"spouse": {
"$ref": "#/definitions/spouse"
},
"kids": {
"$ref": "#/definitions/kids"
}
}
},
"Income": {
"type": "object",
"properties": {
"monthly": {
"type": "number"
},
"yearly": {
"type": "number"
}
}
},
"spouse": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"Income": {
"$ref": "#/definitions/Income"
}
}
},
"kids": {
"type": "array",
"items": {
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "number"
}
}
},
"minItems": 1,
"maxItems": 4
}
},
"type": "object",
"properties": {
"employee": {
"$ref": "#/definitions/employee"
}
}
}
定義索引鍵可用來識別可重複使用的結構描述。 可重複使用的架構定義用於建立片段。 以下提供定義的範例JSON結構描述:
{
"$schema": "https://json-schema.org/draft-04/schema#",
"definitions": {
"address": {
"type": "object",
"properties": {
"street_address": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string" }
},
"required": ["street_address", "city", "state"]
}
},
"type": "object",
"properties": {
"billing_address": { "$ref": "#/definitions/address" },
"shipping_address": { "$ref": "#/definitions/address" }
}
}
上例定義了客戶記錄,其中每個客戶都有發運和計費地址。 地址的結構相同(地址具有街道地址、城市地址和州地址),因此最好不要複製地址。 此外,欄位的新增和刪除也方便您日後進行任何變更。
您可以使用 aem:afProperties 屬性來預先設定JSON結構描述欄位以對應至自訂適用性表單元件。 以下列出範例:
{
"properties": {
"sizeInMB": {
"type": "integer",
"minimum": 16,
"maximum": 512,
"aem:afProperties" : {
"sling:resourceType" : "/apps/fd/af/components/guideTextBox",
"guideNodeClass" : "guideTextBox"
}
}
},
"required": [ "sizeInMB" ],
"additionalProperties": false
}
您可以將下列限制新增至JSON結構元素,以限制適用性表單元件可接受的值:
結構屬性 |
資料類型 |
說明 |
Component |
|
字串 |
指定數值和日期的上界。 預設會包含最大值。 |
|
|
字串 |
指定數值和日期的下限。 預設會包含最小值。 |
|
|
布林值 |
如果為true,則表單元件中指定的數值或日期必須小於為maximum屬性指定的數值或日期。 如果為false,則表單元件中指定的數值或日期必須小於或等於為最大屬性指定的數值或日期。 |
|
|
布林值 |
如果為true,則表單元件中指定的數值或日期必須大於為最小屬性指定的數值或日期。 如果為false,則表單元件中指定的數值或日期必須大於或等於為最小屬性指定的數值或日期。 |
|
|
字串 |
指定元件中允許的字元數量最小。 最小長度必須等於或大於零。 |
|
maxLength |
字串 | 指定元件中允許的字元數上限。 最大長度必須等於或大於零。 |
|
|
字串 |
指定字元的順序。 如果字元符合指定的模式,元件將接受字元。 模式屬性映射至對應的適用性表單元件的驗證模式。 |
|
maxItems |
字串 | 指定陣列中的項目數上限。 最大項目必須等於或大於零。 | |
minItems |
字串 | 指定陣列中的最小項目數。 最小項目必須等於或大於零。 |
適用性Forms不支援下列JSON結構:
為什麼我無法為可重複的子表單拖曳子表單的個別元素(從任何複雜類型產生的結構)(minOccours或maxOccurs值大於1)?
在可重複的子表單中,您必須使用完整的子表單。 如果您只想要選擇性欄位,請使用整個結構並刪除不需要的結構。
我在「內容尋找器」中有一個長而複雜的結構。 如何尋找特定元素?
您有兩個選項:
JSON結構描述檔案的副檔名為何?
JSON結構描述檔案的副檔名必須為.schema.json。 例如, <filename>.schema.json。