Form Templates
Describes the Form.io Form Templating System
Last updated
Was this helpful?
Was this helpful?
import { Formio } from '@formio/js';
import uswds from '@formio/uswds';
// use the USWDS-based template instead of the default
Formio.use(uswds);import { Templates } from '@formio/js';
// override the "input" component template (used by components that contain a text input)
const myInput = (ctx) => `<div class="${ctx.component.type}">${ctx.value}</div>`;
Templates.current.input.form = myInput;import { Templates } from '@formio/js';
// override the "input" and "html" component templates
Templates.current = {
input: {
form: (ctx) => '<div>My custom template</div>'
},
html: {
form: (ctx) => '<div>My other custom template</div>'
}
};Templates.current = {
input: {
form: (ctx) => '<div>Template Overridden!</div>'
}
};Templates.current = {
'input-textfield': {
form: (ctx) => '<div>Template Overridden!</div>'
}
};Templates.current = {
'input-textfield-firstName': {
form: (ctx) => '<div>Template Overridden!</div>'
}
};import { Form } from '@formio/js';
const form = new Form(document.getElementById('formio'), 'https://forms.mysite.com/myproject/myform', {
renderMode: 'html'
});import { Form, Templates } from '@formio/js';
Templates.current = {
input: {
myCustomRenderMode: (ctx) => '<div>bar</div>'
}
};
const form = new Form(document.getElementById('formio'), 'https://forms.mysite.com/myproject/myform', {
renderMode: 'myCustomRenderMode'
});