Home
Symple module

FormField

Form input field with typed values and selectable options.

FormField

#include <icy/symple/form.h>
class FormField

Defined in src/symple/include/icy/symple/form.h:227

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.

List of all members

NameKindOwner
FormFieldfunctionDeclared here
FormFieldfunctionDeclared here
~FormFieldfunctionDeclared here
addOptionfunctionDeclared here
addOptionfunctionDeclared here
setValuefunctionDeclared here
setValuefunctionDeclared here
setValuefunctionDeclared here
setValuefunctionDeclared here
addValuefunctionDeclared here
addValuefunctionDeclared here
addValuefunctionDeclared here
addValuefunctionDeclared here
valuesfunctionDeclared here
valuefunctionDeclared here
intValuefunctionDeclared here
doubleValuefunctionDeclared here
boolValuefunctionDeclared here
FormElementfunctionInherited from FormElement
FormElementfunctionInherited from FormElement
FormElementfunctionInherited from FormElement
operator=functionInherited from FormElement
~FormElementfunctionInherited from FormElement
typefunctionInherited from FormElement
idfunctionInherited from FormElement
labelfunctionInherited from FormElement
setTypefunctionInherited from FormElement
setIdfunctionInherited from FormElement
setLabelfunctionInherited from FormElement
setHintfunctionInherited from FormElement
setErrorfunctionInherited from FormElement
addPagefunctionInherited from FormElement
addSectionfunctionInherited from FormElement
addFieldfunctionInherited from FormElement
getFieldfunctionInherited from FormElement
getFieldfunctionInherited from FormElement
hasFieldfunctionInherited from FormElement
setLivefunctionInherited from FormElement
livefunctionInherited from FormElement
clearElementsfunctionInherited from FormElement
clearfunctionInherited from FormElement
validfunctionInherited from FormElement
numElementsfunctionInherited from FormElement
hasErrorsfunctionInherited from FormElement
hasPagesfunctionInherited from FormElement
rootfunctionInherited from FormElement
_rootvariableInherited from FormElement

Inherited from FormElement

KindNameDescription
functionFormElementConstructs an unbound element (root pointer is null).
functionFormElementConstructs an element bound to the given JSON node.
functionFormElementCopy constructor; copies the root pointer reference (shallow).
functionoperator=Copy-assigns the root pointer reference.
function~FormElement virtual
functiontype constReturns the element type string.
functionid constReturns the element ID string.
functionlabel constReturns the display label string.
functionsetTypeSets the element type. Possible values: page, section, text, text-multi, list, list-multi, checkbox, media, custom
functionsetIdSets the element ID field.
functionsetLabelSets the display label field.
functionsetHintSets the hint/description field shown below the element.
functionsetErrorSets an optional validation error message.
functionaddPageAppends a page child element and returns a handle to it.
functionaddSectionAppends a section child element and returns a handle to it.
functionaddFieldAppends a typed field child element and returns a handle to it. Throws std::invalid_argument if type is not a recognised field type.
functiongetFieldSearches child elements for the field with the given ID.
functiongetFieldPopulates a FormField by searching child elements for the given ID.
functionhasFieldReturns true if any child element has an ID matching the given value.
functionsetLiveSets the live flag on this element. Live elements are used to submit partial form sections (e.g. for auto-complete) without sending the entire form.
functionlive constReturns true if this field is live, meaning the form-processing entity should auto-update this field's value whenever it changes.
functionclearElementsRemoves all child elements whose ID matches the given value.
functionclearClears all fields from the underlying JSON node.
functionvalid constReturns true if the form element is valid.
functionnumElementsReturns the number of child elements.
functionhasErrorsReturns true if any fields have errors.
functionhasPagesReturns true if the form has multiple pages.
functionroot constReturns a reference to the underlying JSON node. Throws std::runtime_error if the root pointer is null.
variable_rootThe root pointer is just a reference to the externally managed JSON value memory.

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()

Defined in src/symple/include/icy/symple/form.h:231

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 = "")

Defined in src/symple/include/icy/symple/form.h:238

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)

Defined in src/symple/include/icy/symple/form.h:245

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)

Defined in src/symple/include/icy/symple/form.h:249

Adds an option whose key and display value are identical.

Parameters

  • value Option string.

setValue

void setValue(std::string_view value)

Defined in src/symple/include/icy/symple/form.h:253

Replaces all current values with a single string value.

Parameters

  • value String value to set.

setValue

void setValue(int value)

Defined in src/symple/include/icy/symple/form.h:257

Replaces all current values with a single integer value.

Parameters

  • value Integer value to set.

setValue

void setValue(double value)

Defined in src/symple/include/icy/symple/form.h:261

Replaces all current values with a single double value.

Parameters

  • value Double value to set.

setValue

void setValue(bool value)

Defined in src/symple/include/icy/symple/form.h:265

Replaces all current values with a single boolean value.

Parameters

  • value Boolean value to set.

addValue

void addValue(std::string_view value)

Defined in src/symple/include/icy/symple/form.h:269

Appends a string value to the values array.

Parameters

  • value String value to append.

addValue

void addValue(int value)

Defined in src/symple/include/icy/symple/form.h:273

Appends an integer value to the values array.

Parameters

  • value Integer value to append.

addValue

void addValue(double value)

Defined in src/symple/include/icy/symple/form.h:277

Appends a double value to the values array.

Parameters

  • value Double value to append.

addValue

void addValue(bool value)

Defined in src/symple/include/icy/symple/form.h:281

Appends a boolean value to the values array.

Parameters

  • value Boolean value to append.

values

json::Value & values()

Defined in src/symple/include/icy/symple/form.h:284

Returns a reference to the JSON array of all values.


value

const

std::string value() const

Defined in src/symple/include/icy/symple/form.h:288

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


intValue

const

int intValue() const

Defined in src/symple/include/icy/symple/form.h:291

Returns the first value parsed as an integer.


doubleValue

const

double doubleValue() const

Defined in src/symple/include/icy/symple/form.h:294

Returns the first value parsed as a double.


boolValue

const

bool boolValue() const

Defined in src/symple/include/icy/symple/form.h:298

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