Back to October

Input Preset

modules/system/assets/toolbox/controls/input-preset/README.md

4.3.01.9 KB
Original Source

Input Preset

Automatically converts text entered in a source input to a formatted value in a destination input. Useful for generating slugs, URLs, file names, or camelCase identifiers from a title field.

Includes a transliteration engine supporting Vietnamese, Latin, Greek, Turkish, Russian, Ukrainian, Czech, Polish, Latvian, Arabic, Persian, Lithuanian, Serbian, Azerbaijani, Romanian, and Belarusian character sets.

Basic Usage

html
<input type="text" id="title" placeholder="Type a title" />
<input type="text"
    data-input-preset="#title"
    data-input-preset-type="slug"
    placeholder="Auto-generated slug" />

JavaScript API

js
$('#slug').inputPreset({
    inputPreset: '#title',
    inputPresetType: 'file'
})

Engine API

js
oc.InputPresetEngine.formatValue({ inputPresetType: 'slug' }, 'My Title')
// Returns: "my-title"

Data Attributes

AttributeDescription
data-input-presetCSS selector for the source input
data-input-preset-typeConversion type: slug (default), url, file, camel, snake, exact, namespace
data-input-preset-closest-parentCSS selector for a common parent scope
data-input-preset-prefix-inputCSS selector for an input whose value prefixes the result
data-input-preset-remove-wordsFilter English stop words (default: true)

Conversion Types

TypeInputOutput
slugMy Blog Postmy-blog-post
urlMy Blog Post/my-blog-post
fileMy Blog Postmy-blog-post
camelMy Blog PostmyBlogPost
snakeMy Blog Postmy_blog_post
namespaceMy Blog PostMyBlogPost
exactMy Blog PostMy Blog Post

Events

EventDescription
oc.inputPreset.beforeUpdateBefore the destination value is updated
oc.inputPreset.afterUpdateAfter the destination value is updated