Skip to content

Commit

Permalink
Better handling of hidden fields and route inferring
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro committed Dec 28, 2018
1 parent 0f9f70f commit 151f437
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/DTD/Concerns/HasGlobalAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function dropZone($value = null)
* @param bool $hidden
* @return $this
*/
public function hidden(?bool $hidden = true)
public function hide(?bool $hidden = true)
{
$this->attributes['hidden'] = $hidden;

Expand Down
4 changes: 3 additions & 1 deletion src/DTD/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ public function encType($value = null)
*/
public function method($value = null)
{
$this->attributes['method'] = $value;
$this->attributes['method'] = $value
? strtoupper($value)
: null;

return $this;
}
Expand Down
13 changes: 13 additions & 0 deletions src/Elements/Concerns/CreatesInputTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ trait CreatesInputTypes
{
abstract public function input($name = null, $label = null) : Input;

public function hidden($name = null, $value = null) : Input
{
$input = $this->input($name);

$input->type('hidden');

if ($value) {
$input->value($value);
}

return $input;
}

public function checkbox($name = null, $label = null) : Input
{
$input = $this->input($name, $label);
Expand Down
7 changes: 5 additions & 2 deletions src/Elements/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Galahad\Aire\Aire;
use Galahad\Aire\Elements\Concerns\CreatesElements;
use Galahad\Aire\Elements\Concerns\CreatesInputTypes;
use Illuminate\Routing\RouteCollection;
use Illuminate\Routing\Router;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Session\Store;
Expand Down Expand Up @@ -330,6 +329,10 @@ protected function initGroup()

protected function inferMethodFromRoute($route_name)
{
if ($this->attributes['method'] !== $this->default_attributes['method']) {
return;
}

if (!$this->router) {
return;
}
Expand All @@ -342,7 +345,7 @@ protected function inferMethodFromRoute($route_name)
return 'HEAD' !== $method;
});

if (1 !== count($methods)) {
if (!count($methods)) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/DTD/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ public function test_method_attribute_can_be_set_and_unset() : void
$form = $this->aire()->form();

$form->method('get');
$this->assertSelectorAttribute($form, 'form', 'method', 'get');
$this->assertSelectorAttribute($form, 'form', 'method', 'GET');

$form->method('post');
$this->assertSelectorAttribute($form, 'form', 'method', 'post');
$this->assertSelectorAttribute($form, 'form', 'method', 'POST');

$form->method(null);
$this->assertSelectorAttributeMissing($form, 'form', 'method');
Expand Down
4 changes: 2 additions & 2 deletions tests/DTD/GlobalAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ public function test_hidden_flag_can_be_set_on_and_off() : void
{
$form = $this->aire()->form();

$form->hidden();
$form->hide();
$this->assertSelectorAttribute($form, 'form', 'hidden');

$form->hidden(false);
$form->hide(false);
$this->assertSelectorAttributeMissing($form, 'form', 'hidden');
}

Expand Down

0 comments on commit 151f437

Please sign in to comment.