-
Hi everyone, For example, when trying 'select' as: const dd = view(select(["Spring", "Summer", "Fall", "Winter"])) I get This doesn't happen, e.g. with 'slider', where this works: const a1_1 = view(slider({
min: 0,
max: 1,
step: 0.01,
format: v => `${Math.round(100 * v)} per cent`,
description: "Zero to one, formatted with a custom function"
})) Any tips for how to correct? Thanks in advance for your time and help! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
.. It feels like the issue is related to Framework’s
I have tried playing around with |
Beta Was this translation helpful? Give feedback.
-
Jeremy’s Inputs relies on the unsafe behavior of the <select name="input" ${multiple ? `multiple size="${size || options.length}"` : ""}> In Hypertext Literal, you have to rewrite this as: <select name="input" multiple=${multiple} size=${multiple ? size || options.length : undefined}> As you also discovered, you’ll probably also need to strip the whitespace around the To make Jeremy’s function select(config = {}) {
let {
value: formValue,
title,
description,
disabled,
submit,
multiple,
size,
options
} = Array.isArray(config) ? {options: config} : config;
options = options.map((o) =>
typeof o === "object" ? o : {value: o, label: o}
);
const form = input({
type: "select",
title,
description,
submit,
attributes: {disabled},
getValue: (input) => {
const selected = Array.prototype.filter
.call(input.options, (i) => i.selected)
.map((i) => i.value);
return multiple ? selected : selected[0];
},
form: html`<form>
<select name="input" multiple=${multiple} size=${multiple ? size || options.length : undefined}>
${options.map(
({value, label, disabled}) =>
html`<option value=${value} selected=${
Array.isArray(formValue)
? formValue.includes(value)
: formValue === value
} disabled=${disabled}>${label}</option>`
)}
</select>
</form>`
});
form.output.remove();
return form;
} I think it will be easier (and more beneficial) to port your application to Observable Inputs than it will be to rewrite Jeremy’s Inputs to use Hypertext Literal. You might find our Legacy Inputs especially helpful. Alternatively, you could avoid using Hypertext Literal, and instead use the unsafe version of import {html} from "npm:@observablehq/stdlib@5/src/html"; |
Beta Was this translation helpful? Give feedback.
-
Thank you @mbostock for this enlightening response! I am excited to continue to adapt and learn. I have implemented 'inputs 3 ways' at the original |
Beta Was this translation helpful? Give feedback.
Jeremy’s Inputs relies on the unsafe behavior of the
html
tagged template literal in notebooks. When you switch it to using Hypertext Literal, you get theinvalid binding
error because it’s using forms of interpolation that Hypertext Literal doesn’t support. Specifically it comes from this part:In Hypertext Literal, you have to rewrite this as:
As you also discovered, you’ll probably also need to strip the whitespace around the
<form>
element; otherwise Hypertext Literal will wrap the form element with a DIV …