Examples
A cookbook of ready-to-adapt schema and UI schema snippets
A cookbook of common patterns you can copy and adapt. Each recipe shows the Schema and, where relevant, the UI Schema. For an explanation of each type, see Field Types.
These snippets show individual properties. Remember that the root of a Wicket schema is an object — place these inside its properties.
Dropdown
A single-select drop-down backed by an enum.
"status": {
"type": "string",
"enum": ["active", "duplicate", "defunct-acquired", "delete"]
}"status": {
"ui:i18n": {
"label": { "en": "Status", "fr": "Statut" },
"enumNames": {
"en": ["Active", "Duplicate", "Defunct/Acquired", "Delete"],
"fr": ["Actif", "Dupliqué", "Inactif/Acquis", "Supprimer"]
}
}
}Dropdown with an "Other" custom value
Lets the user pick from a list or enter a free-text value when they choose "Other." Unlike a oneOf approach, this does not force the field to be required.
"joinreasons": {
"type": "object",
"properties": {
"value": {
"type": "string",
"enum": ["advocacy", "events", "training", "other"]
},
"custom_value": {
"type": "string"
}
}
}"joinreasons": {
"ui:field": "ObjectEnumWithCustomValueField",
"ui:options": { "customValueEnum": "other" },
"value": {
"ui:i18n": {
"label": { "en": "Select Join Reason" },
"enumNames": {
"en": ["Advocacy", "Events & Networking", "Training", "Other"]
}
}
},
"custom_value": {
"ui:i18n": { "label": { "en": "Enter Other Reason" } }
}
}Multi-select checkboxes
Store multiple selected values as an array of strings.
"resources": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "string",
"enum": ["webinars", "mygideon", "listserv", "job_board"]
}
}"resources": {
"ui:widget": "checkboxes",
"ui:i18n": {
"label": { "en": "Which resources do you hope to use?" },
"enumNames": {
"en": ["Live and archived webinars", "Resource library", "Listserv access", "Job board listings"]
}
}
}To render the checkboxes in a grid, add ui:options:
"resources": {
"ui:widget": "checkboxes",
"ui:options": {
"grid": true,
"descriptionIsMarkdown": true
}
}Conditional fields
Show a different follow-up field depending on the value selected in a driving field. The UI Schema's enumFieldOptions must list the same conditions as the Schema's oneOf branches.
"conditional": {
"type": "object",
"oneOf": [
{
"properties": {
"field_with_condition": { "type": "string", "enum": ["condition1"] },
"1st_conditional_field": { "type": "string", "enum": ["opt1", "opt2"] }
},
"additionalProperties": false
},
{
"properties": {
"field_with_condition": { "type": "string", "enum": ["condition2"] },
"2nd_conditional_field": { "type": "string", "enum": ["opt1", "opt2"] }
},
"additionalProperties": false
}
]
}"conditional": {
"ui:field": "ObjectOneOfEnumField",
"ui:options": {
"enumField": "field_with_condition",
"enumFieldType": "string",
"enumFieldOptions": ["condition1", "condition2"]
},
"ui:i18n": {
"enumFieldOptionsNames": {
"en": ["Condition One", "Condition Two"],
"fr": ["Condition Un", "Condition Deux"]
}
}
}Currency
Validate a currency-formatted string. Wicket provides a money reference to avoid hand-writing the pattern:
"amount": {
"$ref": "wicket://schemas/money?currency=USD",
"type": "string",
"x-currency": "USD"
}"amount": {
"type": "string",
"pattern": "^\\$?\\d+(\\.\\d{2})?$",
"x-currency": "USD"
}Shared enum list (definitions)
Define a list once in definitions and reuse it across multiple fields — handy when several fields share the same options.
{
"type": "object",
"properties": {
"primary_code": {
"type": "string",
"$ref": "#/definitions/codes"
},
"other_codes": {
"type": "array",
"uniqueItems": true,
"items": { "$ref": "#/definitions/codes" }
}
},
"definitions": {
"codes": {
"type": "string",
"enum": ["ADVA", "PDMA", "ADEF", "ADLM"],
"enumNames": [
"Advertising Agencies",
"Promotional Products & Services",
"Eco Friendly Promotional Products",
"List Management"
]
}
}
}Dropdown sourced from Wicket data
Populate options from live Wicket records using a wicket:// reference.
"audit_period": {
"$ref": "wicket://schemas/resource_types/audit_periods"
}Add include_default to preselect the entity's default value:
"audit_period": {
"$ref": "wicket://schemas/resource_types/audit_periods?include_default"
}Reference organizations (only supported for organizations, not people), passing sorts and Ransack filters:
"partner": {
"type": "string",
"$ref": "wicket://schemas/organizations?sorts=legal_name_en&membership_entries_membership_slug_matches=strategic-alliance%25"
}Integer with min/max (e.g. a year)
"year": {
"type": "integer",
"minimum": 1900,
"maximum": 2100
}