Skip to content

Commit

Permalink
Merge pull request #79 from theshaunwalker/fix-#78
Browse files Browse the repository at this point in the history
update views to use correct name
  • Loading branch information
kristijanhusak committed Apr 19, 2015
2 parents efcc902 + b1c6f6e commit 50dfaa7
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 9 deletions.
13 changes: 12 additions & 1 deletion src/Kris/LaravelFormBuilder/Fields/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function render(array $options = [], $showLabel = true, $showField = true
$this->template,
[
'name' => $this->name,
'nameKey' => $this->getNameKey(),
'type' => $this->type,
'options' => $options,
'showLabel' => $showLabel,
Expand Down Expand Up @@ -197,6 +198,16 @@ public function setName($name)
return $this;
}

/**
* Get dot notation key for fields
*
* @return string
**/
public function getNameKey()
{
return $this->transformKey($this->name);
}

/**
* Get field options
*
Expand Down Expand Up @@ -339,7 +350,7 @@ protected function addErrorClass(&$options)
{
$errors = $this->formHelper->getRequest()->getSession()->get('errors');

if ($errors && $errors->has($this->name)) {
if ($errors && $errors->has($this->getNameKey())) {
$errorClass = $this->formHelper->getConfig('defaults.wrapper_error_class');

if ($options['wrapper'] && !str_contains($options['wrapper']['class'], $errorClass)) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<?php endif; ?>

<?php if ($showError && isset($errors)): ?>
<?php foreach ($errors->get(array_get($options, 'real_name', $name)) as $err): ?>
<?php foreach ($errors->get($nameKey) as $err): ?>
<div <?= $options['errorAttrs'] ?>><?= $err ?></div>
<?php endforeach; ?>
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion src/views/child_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<?php endif; ?>

<?php if ($showError && isset($errors)): ?>
<?php foreach ($errors->get(array_get($options, 'real_name', $name)) as $err): ?>
<?php foreach ($errors->get($nameKey) as $err): ?>
<div <?= $options['errorAttrs'] ?>><?= $err ?></div>
<?php endforeach; ?>
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion src/views/choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<?php endif; ?>

<?php if ($showError && isset($errors)): ?>
<?php foreach ($errors->get(array_get($options, 'real_name', $name)) as $err): ?>
<?php foreach ($errors->get($nameKey) as $err): ?>
<div <?= $options['errorAttrs'] ?>><?= $err ?></div>
<?php endforeach; ?>
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion src/views/collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<?php endif; ?>

<?php if ($showError && isset($errors)): ?>
<?php foreach ($errors->get(array_get($options, 'real_name', $name)) as $err): ?>
<?php foreach ($errors->get($nameKey) as $err): ?>
<div <?= $options['errorAttrs'] ?>><?= $err ?></div>
<?php endforeach; ?>
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion src/views/radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<?php endif; ?>

<?php if ($showError && isset($errors)): ?>
<?php foreach ($errors->get(array_get($options, 'real_name', $name)) as $err): ?>
<?php foreach ($errors->get($nameKey) as $err): ?>
<div <?= $options['errorAttrs'] ?>><?= $err ?></div>
<?php endforeach; ?>
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion src/views/select.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


<?php if ($showError && isset($errors)): ?>
<?php foreach ($errors->get(array_get($options, 'real_name', $name)) as $err): ?>
<?php foreach ($errors->get($nameKey) as $err): ?>
<div <?= $options['errorAttrs'] ?>><?= $err ?></div>
<?php endforeach; ?>
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion src/views/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<?php endif; ?>

<?php if ($showError && isset($errors)): ?>
<?php foreach ($errors->get(array_get($options, 'real_name', $name)) as $err): ?>
<?php foreach ($errors->get($nameKey) as $err): ?>
<div <?= $options['errorAttrs'] ?>><?= $err ?></div>
<?php endforeach; ?>
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion src/views/textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<?php endif; ?>

<?php if ($showError && isset($errors)): ?>
<?php foreach ($errors->get(array_get($options, 'real_name', $name)) as $err): ?>
<?php foreach ($errors->get($nameKey) as $err): ?>
<div <?= $options['errorAttrs'] ?>><?= $err ?></div>
<?php endforeach; ?>
<?php endif; ?>
Expand Down
2 changes: 2 additions & 0 deletions tests/Fields/ButtonTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function it_creates_button()

$expectedViewData = [
'name' => 'some_button',
'nameKey' => 'some_button',
'type' => 'button',
'options' => $expectedOptions,
'showLabel' => true,
Expand Down Expand Up @@ -75,6 +76,7 @@ public function it_can_change_template_with_options()

$expectedViewData = [
'name' => 'some_submit',
'nameKey' => 'some_submit',
'type' => 'submit',
'options' => $expectedOptions,
'showLabel' => true,
Expand Down
1 change: 1 addition & 0 deletions tests/Fields/InputTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function it_prevents_rendering_label_for_hidden_field()

$expectedViewData = [
'name' => 'hidden_id',
'nameKey' => 'hidden_id',
'type' => 'hidden',
'options' => $expectedOptions,
'showLabel' => false,
Expand Down
1 change: 1 addition & 0 deletions tests/Fields/StaticTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function it_creates_static_field()

$expectedViewData = [
'name' => 'some_static',
'nameKey' => 'some_static',
'type' => 'static',
'options' => $expectedOptions,
'showLabel' => true,
Expand Down

0 comments on commit 50dfaa7

Please sign in to comment.