Dependent values
The following form demonstrates the use of VisualData to query and record dependent values (the classical case is the country-state-city relationship) and to easily create and store them on your wiki through a couple of maintenance scripts. It uses the schema VisualDataSchema:Dependent_values created through the Schema Builder (see special page Special:ManageSchemas then open the schema "Dependent values").
The first field (country) is a OOUI DropdownInputWidget with items taken from the template Template:Countries.
The second field (state) is a LookupElement with query
[[name::<country>]][[states/name::<value>~]]
where <country>
is the name of the first field and <value>
is the value being inserted in the input.. The requested printout is states/name
that matches the path properties/states/items/properties/name
in the schema VisualDataSchema:Country. (where only relevant property names have to be concatenated, leaving aside properties
and items
that belong to the schema structure). The query will search json data related to the schema "Country" with value of the property name
equal to the value of the first field, and value of the property states/name
equal to the state input value.
The third field (city) uses this query
[[name::<country>]][[states/name::<state>]][[states/cities/name::<value>~]]
The query as above will search json data related to the schema "Country" with value of the property name
equal to the value of the first field, value of the property states/name
equal to the second field, and value of the property states/cities/name
equal to the city input value. The requested printout in this case is states/cities/name
.
The query searches within a database of 250 wiki pages with json content model like Data:Countries/Afghanistan, containing more than 620,000 entries in total.
The database can been created downloading this data countries%2Bstates%2Bcities.json from github.com/dr5hn/countries-states-cities-database and then importing them on your wiki using the following maintenance command:
php extensions/VisualData/maintenance/ImportData.php --file "[path-to-the following-file]/countries+states+cities.json" --schema Country --pagename-formula "Data:countries/<name>" --main-slot
The script takes only a few minutes to create all the required entries (including the related schema if it does not exist) and the data can be rebuilt any time through the following command:
php extensions/VisualData/maintenance/RebuildData.php
This is the wikitext used to create the form itself:
{{#visualdataform: Dependent values |title = Dependent values |action = create |edit-page = |return-page = |view = inline |popup-size = medium |css-class = |pagename-formula = |edit-freetext = false |edit-categories = false |edit-content-model = false |default-categories = |default-content-model = json |layout-align = top |popup-help = true |submit-button-text = |layout = tabs |submit-button-text = |validate-button-text = }}
Have fun using your wiki as an open-source database management system !!
See also
- Demo VisualData 1.0
- New task
- Page upload
- CRUD
- Result formats
- Dependent values
- Geolocation
- Queries
- Query cities (join queries)
- Dynamic catalogue
- Datatable cards
- Nested schemas
- Carousel
- Table mode
- Lua
- Official docs
support & questions: support at topway.it