Symple module

FormField

[Form]({#ref classicy_1_1smpl_1_1Form #}) input field with typed values and selectable options.

FormField

#include <icy/symple/form.h>

Inherits: FormElement

Form input field with typed values and selectable options.

Values are stored as strings in a JSON array. Typed accessors (intValue, doubleValue, boolValue) parse the first string on demand.

Public Methods

ReturnNameDescription
FormFieldConstructs an unbound field (root pointer is null).
FormFieldConstructs a field bound to the given JSON node.
voidaddOptionAdds a labelled option for list-based fields.
voidaddOptionAdds an option whose key and display value are identical.
voidsetValueReplaces all current values with a single string value.
voidsetValueReplaces all current values with a single integer value.
voidsetValueReplaces all current values with a single double value.
voidsetValueReplaces all current values with a single boolean value.
voidaddValueAppends a string value to the values array.
voidaddValueAppends an integer value to the values array.
voidaddValueAppends a double value to the values array.
voidaddValueAppends a boolean value to the values array.
json::Value &valuesReturns a reference to the JSON array of all values.
std::stringvalue constReturns the first value as a string. Most field types (except multi-value) only use a single value.
intintValue constReturns the first value parsed as an integer.
doubledoubleValue constReturns the first value parsed as a double.
boolboolValue constReturns the first value parsed as a boolean. Treats "1", "true", and "on" as true; all other strings as false.

FormField

FormField()

Constructs an unbound field (root pointer is null).


FormField

FormField(json::Value & root, std::string_view type, std::string_view id, std::string_view label)

Constructs a field bound to the given JSON node.

Parameters

  • root JSON node to bind to.

  • type Field type string (e.g. "text", "list").

  • id Optional field ID.

  • label Optional display label.


addOption

void addOption(std::string_view key, std::string_view value)

Adds a labelled option for list-based fields.

Parameters

  • key Option key sent on submit.

  • value Display label for the option.


addOption

void addOption(std::string_view value)

Adds an option whose key and display value are identical.

Parameters

  • value Option string.

setValue

void setValue(std::string_view value)

Replaces all current values with a single string value.

Parameters

  • value String value to set.

setValue

void setValue(int value)

Replaces all current values with a single integer value.

Parameters

  • value Integer value to set.

setValue

void setValue(double value)

Replaces all current values with a single double value.

Parameters

  • value Double value to set.

setValue

void setValue(bool value)

Replaces all current values with a single boolean value.

Parameters

  • value Boolean value to set.

addValue

void addValue(std::string_view value)

Appends a string value to the values array.

Parameters

  • value String value to append.

addValue

void addValue(int value)

Appends an integer value to the values array.

Parameters

  • value Integer value to append.

addValue

void addValue(double value)

Appends a double value to the values array.

Parameters

  • value Double value to append.

addValue

void addValue(bool value)

Appends a boolean value to the values array.

Parameters

  • value Boolean value to append.

values

json::Value & values()

Returns a reference to the JSON array of all values.


value

const

std::string value() const

Returns the first value as a string. Most field types (except multi-value) only use a single value.


intValue

const

int intValue() const

Returns the first value parsed as an integer.


doubleValue

const

double doubleValue() const

Returns the first value parsed as a double.


boolValue

const

bool boolValue() const

Returns the first value parsed as a boolean. Treats "1", "true", and "on" as true; all other strings as false.