Public
Edited
Mar 6, 2024
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
db_schema = {
const { Form, Field, Submit, Answer } = Namespaces;
// Partial schema - only necessary attributes are defined
const schema = {
// Form definition properties
[Form.id]: {":db/unique": ":db.unique/identity"},
// [Form.title]: {},
[Form.fields]: {":db/valueType": ":db.type/ref",
":db/cardinality": ":db.cardinality/many"},
// [Form.instant] : {} // create or updated date

// Form field properties
[Field.id]: {":db/unique": ":db.unique/identity"},
// [Field.title]: {}
// [Field.scalar]: {}
// [Field.format]: {}
// [Field.type]: {}

// Submission properties
[Submit.id]: {":db/unique": ":db.unique/identity"},
[Submit.form]: {":db/valueType": ":db.type/ref",
":db/cardinality": ":db.cardinality/one"},
[Submit.time]: {":db/valueType": ":db.type/ref",
":db/cardinality": ":db.cardinality/one"},
[Submit.answers]: {":db/valueType": ":db.type/ref",
":db/cardinality": ":db.cardinality/many",
":db/isComponent": true},
// [Submit.instant]: {} // create or updated date

// Answer properties
[Answer.id]: {":db/unique": ":db.unique/identity"},
[Answer.question]: {":db/valueType": ":db.type/ref",
":db/cardinality": ":db.cardinality/one"},
// [Answer.value]: {}
};

return schema;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function getPersonFormDefinition() {
const { Form, Field } = Namespaces;
return [
// Top-level form information
{
":db/id": -1,
[Form.id]: "person-form",
[Form.title]: "Person Form",
[Form.fields]: [-2, -3, -4],
[Form.instant]: Temporal.Now.instant().epochSeconds
},
// Individual form fields
{
":db/id": -2,
[Field.id]: "first-name",
[Field.title]: "First name",
[Field.format]: Formats.input,
[Field.scalar]: Scalars.string,
},
{
":db/id": -3,
[Field.id]: "last-name",
[Field.title]: "Last name",
[Field.format]: Formats.input,
[Field.scalar]: Scalars.string,
},
{
":db/id": -4,
[Field.id]: "important-date",
[Field.title]: "Important Date",
[Field.format]: Formats.date_iso_8601,
[Field.scalar]: Scalars.string,
[Field.type]: InputTypes.text,
}
];

}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function updateDateField() {
const { Field, Form } = Namespaces;
const updatedField = {
[Field.id]: "important-date",
[Field.format]: Formats.date_utc,
[Field.type]: InputTypes.date
}
// Need to update form instant (modified) time for later use
const updatedForm = {
[Form.id]: "person-form",
[Form.instant]: Temporal.Now.instant().epochSeconds
}

transact([updatedForm, updatedField]);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more