Public
Edited
Dec 14, 2023
Insert cell
Insert cell
Insert cell
Insert cell
viewof fakeSource = Inputs.input()
Insert cell
// set helper
function set(input, value) {
input.value = value;
// in this case firing this event seems to be interfering with localStorageView
input.dispatchEvent(new Event("input", {bubbles: true}));
}
Insert cell
Inputs.button([
["Set to example", () => set(viewof fakeSource, 'example')],
["Set to ''", () => set(viewof fakeSource, '')]
])
Insert cell
viewof inputView = Inputs.textarea()
Insert cell
viewof inputStorage = localStorageView("inputStorage", {defaultValue: "default"})
Insert cell
Inputs.bind(viewof inputView, viewof fakeSource)
Insert cell
// according to the docs this should be this way round to have the page load work correctly
// but it yields this error:
// Uncaught TypeError: e.closest is not a function
// at inputs.min.js:40:1444
Inputs.bind(viewof fakeSource, viewof inputStorage)
// The other way round doesn't error, but indeed it doesn't load the default value on page load.
// Inputs.bind(viewof inputStorage, viewof fakeSource)
Insert cell
Insert cell
viewof example1 = Inputs.range()
Insert cell
Insert cell
Insert cell
Insert cell
viewof example1storage = localStorageView("example1")
Insert cell
Insert cell
localStorageView.value
Insert cell
Insert cell
// Note you need to get these the right way round to have the page load work correctly
Inputs.bind(viewof example1, viewof example1storage)
Insert cell
Insert cell
Insert cell
viewof jsonView = localStorageView("json", {
json: true
})
Insert cell
jsonView
Insert cell
viewof jsonView.value
Insert cell
Insert cell
{
viewof jsonView.value = {
rnd: Math.random()
};
viewof jsonView.dispatchEvent(new Event("input", { bubbles: true }));
}
Insert cell
Insert cell
viewof example2 = Inputs.textarea()
Insert cell
localStorageView("example2", {
bindTo: viewof example2
})
Insert cell
Insert cell
viewof example3 = Inputs.bind(Inputs.textarea(), localStorageView("example3"))
Insert cell
Insert cell
import { footer } from "@endpointservices/endpoint-services-footer"
Insert cell
footer
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