HandlebarsHelper

HandlebarsHelper

Methods

(static) bindModel(field, options) → {string}

Source:

Usage: {{bindModel 'fieldName' value='suffix'}}

Generates: id="field-name-suffix" name="field-name" data-model="fieldName" data-feedback="fieldName" value="demo"

Usage: {{bindModel 'fieldName[x].sub' value='demo' x=123}}

Generates: data-model="fieldName[123].sub" data-feedback="fieldName[123].sub" name="field-name-123_sub"
id="field-name-123_sub-demo" value="demo"

Usage: {{bindModel 'fieldName[bar].sub' value='demo' bar='abc'}}

Generates: data-model="fieldName.abc.sub" data-feedback="fieldName[abc].sub" name="field-name_abc_sub"
id="field-name_abc_sub-demo" value="demo"

Parameters:
Name Type Description
field string

The field name to convert to compliant id, name, data-model, and data-feedback attributes

options Object

The handlebars context. Always passed in as the final argument.

Properties
Name Type Attributes Description
hash.value string <optional>

The value tacked on to the end of the field string (useful for radio and checkbox)

Returns:

Compliant HTML generating the id, name, data-model, and data-feedback attributes

Type
string

(static) dasherize(str) → {string}

Source:

Usage: {{feedback 'fieldName[x].sub'}}

Generates: field-name[x]_sub

Parameters:
Name Type Description
str string

The input string to make HTML compliant (convert to dashes)

Returns:

HTML complicant / dasherized string

Type
string

(static) feedback(field, options) → {string}

Source:

Usage: {{feedback 'fieldName'}}

Generates: data-feedback="fieldName"

Usage: {{feedback 'fieldName[x].sub' value='demo' x=123}}

Generates: data-feedback="fieldName[123].sub"

Usage: {{feedback 'fieldName[bar].sub value='demo' bar='abc'}}

Generates: data-feedback="fieldName[abc].sub"

Parameters:
Name Type Description
field string

The field name to convert to a compliant data-feedback attribute

options Object

The handlebars context. Always passed in as the final argument.

Returns:

Compliant HTML generating the data-feedback attribute

Type
string

(static) formAttr(field, options) → {string}

Source:

Usage: {{formAttr 'fieldName[x].sub' 'id, for' value='demo' x=123}}

Generates: id="field-name-123_sub-demo" for="field-name-123_sub-demo" value="demo"

Usage: {{feedback 'fieldName[bar].sub value='demo' bar='abc'}}

Generates: id="field-name_abc_sub-demo" for="field-name_abc_sub-demo" value="demo"

Parameters:
Name Type Description
field string

The field name to convert to a compliant data-feedback attribute

options Object

The handlebars context. Always passed in as the final argument.

Properties
Name Type Attributes Description
hash.value string <optional>

The value tacked on to the end of the field string (useful for radio and checkbox)

noValueAttr boolean <optional>

when options.noValueAttr is set to true,
then it will not generate the "value" attribute in the DOM.

Returns:

Compliant HTML generating the data-feedback attribute

Type
string

(static) injectFieldIndices(field, indexMap, options) → {string}

Source:

Usage: injectFieldIndices('test[x]-thisIsRegular-y', {x: 123, y: 456} and 'foo[x].abc', x='bar');

Generates: 'test[123]-thisIsRegular-y' and 'foo.bar.abc'

if options.forceArrayNotation is set then:

Generates: 'test[123]-thisIsRegular-y' and 'foo[bar].abc'

Parameters:
Name Type Description
field string

The field name

indexMap Object

A map of variables

options Object

named parameters

Properties
Name Type Attributes Default Description
forceArrayNotation boolean <optional>
false

Force the usage of [] insetad of . for string values.

Returns:

the field string with array variables substituted

Type
string

(static) labelFor(field, options) → {string}

Source:

Usage: {{labelFor 'fieldName' value="suffix"}}

Generates: for="field-name-suffix"

Usage: {{labelFor 'fieldName[x].sub' value="demo" x=123}}

Generates: for="field-name-123_sub-demo"

Usage: {{labelFor 'fieldName[bar].sub' value="demo" bar="abc"}}

Generates: for="field-name_abc_sub-demo"

Parameters:
Name Type Attributes Description
field string

The field name to convert to a compliant "for" attribute

options Object

The handlebars context. Always passed in as the final argument.

option.hash.value string <optional>

The value tacked on to the end of the field string (useful for radio and checkbox)

Returns:

Compliant HTML generating the "for" attribute

Type
string