FormField
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
| Return | Name | Description |
|---|---|---|
FormField | Constructs an unbound field (root pointer is null). | |
FormField | Constructs a field bound to the given JSON node. | |
void | addOption | Adds a labelled option for list-based fields. |
void | addOption | Adds an option whose key and display value are identical. |
void | setValue | Replaces all current values with a single string value. |
void | setValue | Replaces all current values with a single integer value. |
void | setValue | Replaces all current values with a single double value. |
void | setValue | Replaces all current values with a single boolean value. |
void | addValue | Appends a string value to the values array. |
void | addValue | Appends an integer value to the values array. |
void | addValue | Appends a double value to the values array. |
void | addValue | Appends a boolean value to the values array. |
json::Value & | values | Returns a reference to the JSON array of all values. |
std::string | value const | Returns the first value as a string. Most field types (except multi-value) only use a single value. |
int | intValue const | Returns the first value parsed as an integer. |
double | doubleValue const | Returns the first value parsed as a double. |
bool | boolValue const | Returns 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
rootJSON node to bind to.typeField type string (e.g. "text", "list").idOptional field ID.labelOptional display label.
addOption
void addOption(std::string_view key, std::string_view value)Adds a labelled option for list-based fields.
Parameters
keyOption key sent on submit.valueDisplay label for the option.
addOption
void addOption(std::string_view value)Adds an option whose key and display value are identical.
Parameters
valueOption string.
setValue
void setValue(std::string_view value)Replaces all current values with a single string value.
Parameters
valueString value to set.
setValue
void setValue(int value)Replaces all current values with a single integer value.
Parameters
valueInteger value to set.
setValue
void setValue(double value)Replaces all current values with a single double value.
Parameters
valueDouble value to set.
setValue
void setValue(bool value)Replaces all current values with a single boolean value.
Parameters
valueBoolean value to set.
addValue
void addValue(std::string_view value)Appends a string value to the values array.
Parameters
valueString value to append.
addValue
void addValue(int value)Appends an integer value to the values array.
Parameters
valueInteger value to append.
addValue
void addValue(double value)Appends a double value to the values array.
Parameters
valueDouble value to append.
addValue
void addValue(bool value)Appends a boolean value to the values array.
Parameters
valueBoolean value to append.
values
json::Value & values()Returns a reference to the JSON array of all values.
value
const
std::string value() constReturns the first value as a string. Most field types (except multi-value) only use a single value.
intValue
const
int intValue() constReturns the first value parsed as an integer.
doubleValue
const
double doubleValue() constReturns the first value parsed as a double.
boolValue
const
bool boolValue() constReturns the first value parsed as a boolean. Treats "1", "true", and "on" as true; all other strings as false.
