Skip to content

Commit

Permalink
Allow ability to customise the ReactFormField value pass to the input…
Browse files Browse the repository at this point in the history
… field on the front end
  • Loading branch information
Maxime Rainville committed Jul 30, 2023
1 parent 463ef30 commit 224f2a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/ReactFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ abstract class ReactFormField extends FormField implements ReactComponent
{

/**
* Whether an input taf shoulde be rendered when using the React component
* Whether an input tag should be rendered when using the React component
* in an entwine form. If the React implementation of the field does not output
* an input tag (or someother HTML form field), this should be set to true.
* an input tag (or some other HTML form field), this should be set to true.
* @var bool
*/
protected $renderInput = false;
Expand Down Expand Up @@ -45,7 +45,7 @@ public function getProps(): array
{
return [
'name' => $this->getName(),
'value' => $this->Value(),
'value' => $this->InputValue(),
'extraClass' => $this->extraClass(),
'id' => $this->ID(),
'disabled' => $this->isDisabled(),
Expand All @@ -69,4 +69,22 @@ public function HiddenID(): string
{
return $this->ID() . '_HiddenValueField';
}

/**
* Convert the value to what will be rendered in thi input on the front end
*/
public function InputValue(): string
{
return $this->Value();
}


public function getSchemaData()
{
$schema = parent::getSchemaData();

$schema = array_merge($schema, $this->getProps());

return $schema;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if $RenderInput %>
<input name="$Name" value="$Value" id="$HiddenID" type="hidden" />
<input name="$Name" value="$InputValue" id="$HiddenID" type="hidden" />
<% end_if %>

<div $AttributesHTML></div>

0 comments on commit 224f2a3

Please sign in to comment.