Component
Code input
<DomCodeInput>A form input for code or structured text. It progressively enhances to CodeMirror from a CDN and falls back to a textarea if loading fails.
Playground
Try every prop live
Code input playground
The enhanced editor is loaded after mount. If the CDN is unavailable, the textarea fallback still works.
Enhanced editor is optional.
Playground.vuevue
<script setup>
import { reactive } from 'vue';
import { DomCodeInput } from '@getdom/studio/vue';
const data = reactive({
"modelValue": "{\n\t\"name\": \"DOM Studio\",\n\t\"editable\": true\n}",
"id": "",
"name": "",
"label": "Configuration",
"description": "Enhanced editor is optional.",
"placeholder": "",
"required": false,
"disabled": false,
"readOnly": false,
"invalid": false,
"errors": {},
"visible": true,
"validators": [],
"validateOnBlur": true,
"chrome": "field",
"lang": "json",
"rows": 8,
"editor": true
});
</script>
<template>
<DomCodeInput
v-bind="data"
@update:modelValue="data.modelValue = $event"
/>
</template>Demo
Progressive editor
Useful for JSON, prompts, templates, snippets, and other structured text inside forms.
Loads an enhanced editor from a CDN when available; otherwise this remains a textarea.
CodeField.vuevue
<script setup>
import { ref } from 'vue';
import { DomCodeInput } from '../../../lib/vue';
const code = ref(`{
\t"name": "DOM Studio",
\t"editable": true,
\t"theme": "token-based"
}`);
</script>
<template>
<div class="w-full max-w-2xl">
<DomCodeInput
v-model="code"
label="Configuration"
description="Loads an enhanced editor from a CDN when available; otherwise this remains a textarea."
lang="json"
:rows="8"
/>
</div>
</template>
Reference
Props
Control props
| Name | Type | TS | Default | Description |
|---|---|---|---|---|
modelValue | string | string | '' | Code text. |
lang | 'text' | 'json' | 'js' | 'html' | 'css' | 'vue' | 'md' | string | 'text' | Language hint for the optional enhanced editor. |
rows | number | number | 10 | Textarea fallback rows. |
editor | boolean | boolean | true | Attempt to load the enhanced editor from the CDN. |
Field props
| Name | Type | TS | Default | Description |
|---|---|---|---|---|
id | string | string | '' | Optional ID override. By default parent forms derive the input ID from the field path using underscores. |
name | string | string | '' | Local field name. Parent forms derive the full field path and native HTML name from the form hierarchy. |
label | string | string | '' | Visible field label. |
description | string | string | '' | Optional helper copy below the field. |
placeholder | string | string | '' | Placeholder shown when the control is empty. |
required | boolean | boolean | false | Mark the field as required. |
disabled | boolean | boolean | false | Disable field interaction. |
readOnly | boolean | boolean | false | Show the value but prevent editing. |
invalid | boolean | boolean | false | Mark the field invalid. |
errors | array | object | string | Array< | {} | Validation errors for this field. |
visible | boolean | boolean | true | Show or hide the field. |
validators | array | Array<unknown> | [] | Validators attached to this field. Use functions in Vue code, or serializable records such as { name: "minLength", props: { min: 2 } } in generated schemas. |
validateOnBlur | boolean | boolean | true | Run validators when the field loses focus. |
chrome | 'field' | false | string | 'field' | Render default field chrome, or false to render only the control while keeping form state wiring. |
Auto-generated from Code input.props and inline _edit hints.
Events
| Name | Payload | Description |
|---|---|---|
| @update:modelValue | string | Fired when the code changes. |
| @focus | — | Fired when the input receives focus. |
| @blur | — | Fired when the input loses focus. |
Names auto-detected from defineEmits and source emit() calls; payload and description from __doc.events when present.