43 return ($value ===
'' || array_key_exists($value, $this->
getOptions()));
59 $clone = parent::withNameFrom($source);
61 foreach ($clone->dependant_fields as $option_value => $fields) {
64 $named_inputs[
$key] =
$input->withNameFrom($source);
66 $clone->dependant_fields[$option_value] = $named_inputs;
74 public function withOption(
string $value,
string $label,
string $byline = null, $dependant_fields = null) :
C\
Input\Field\
Radio 77 $clone->options[$value] = $label;
78 if (!is_null($byline)) {
79 $clone->bylines[$value] = $byline;
98 if (!array_key_exists($value, $this->bylines)) {
101 return $this->bylines[$value];
110 if (!array_key_exists($value, $this->dependant_fields)) {
113 return $this->dependant_fields[$value];
121 if ($this->getName() === null) {
122 throw new \LogicException(
"Can only collect if input has a name.");
124 $value = $post_input->
getOr($this->getName(),
"");
128 $clone->content = $this->applyOperationsTo($value);
129 if ($clone->content->isError()) {
130 return $clone->withError(
"" . $clone->content->error());
134 if (is_null($dep_fields)) {
135 $clone->content = $this->applyOperationsTo($value);
142 foreach ($dep_fields as
$name => $field) {
143 $filled = $field->withInput($post_input);
144 $content = $filled->getContent();
146 if ($content->isOk()) {
149 $clone = $clone->withError(self::DEPENDANT_FIELD_ERROR);
152 $clone->dependant_fields[$value][
$name] = $filled;
154 $clone->content = $clone->applyOperationsTo(
$values);
157 if ($clone->getError()) {
158 $clone->content = $clone->data_factory->error($clone->getError());
getOr($name, $default)
Get a named value from the data and fallback to default if that name does not exist.
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
Describes how Input-Elements want to interact with posted data.
Interface to be extended by components that have the possibility to bind to Javascript.