Skip to content

Commit

Permalink
optimize form
Browse files Browse the repository at this point in the history
  • Loading branch information
z-song committed Feb 20, 2017
1 parent bb3369e commit 9cf0202
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,20 @@ public function setWidth($fieldWidth = 8, $labelWidth = 2)
return $this;
}

/**
* Set view for form.
*
* @param string $view
*
* @return $this
*/
public function setView($view)
{
$this->builder()->setView($view);

return $this;
}

/**
* Tools setting for form.
*
Expand Down
37 changes: 36 additions & 1 deletion src/Form/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class Builder
'field' => 8,
];

/**
* View for this form.
*
* @var string
*/
protected $view = 'admin::form';

/**
* Builder constructor.
*
Expand Down Expand Up @@ -206,6 +213,20 @@ public function getAction()
return '';
}

/**
* Set view for this form.
*
* @param string $view
*
* @return $this
*/
public function setView($view)
{
$this->view = $view;

return $this;
}

/**
* Get fields of this builder.
*
Expand All @@ -216,6 +237,20 @@ public function fields()
return $this->fields;
}

/**
* Get specify field.
*
* @param string $name
*
* @return mixed
*/
public function field($name)
{
return $this->fields()->first(function (Field $field) use ($name) {
return $field->column() == $name;
});
}

/**
* @return array
*/
Expand Down Expand Up @@ -464,7 +499,7 @@ public function render()
'width' => $this->width,
];

return view('admin::form', $data)->render();
return view($this->view, $data)->render();
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
use Encore\Admin\Admin;
use Encore\Admin\Form;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Support\Facades\Validator;

/**
* Class Field.
*
* @method Field default($value) set field default value
*/
class Field
class Field implements Renderable
{
/**
* Element id.
Expand Down Expand Up @@ -725,6 +726,14 @@ public function render()
return view($this->getView(), $this->variables());
}

/**
* @return string
*/
public function __toString()
{
return $this->render()->render();
}

/**
* @param $method
* @param $arguments
Expand Down

0 comments on commit 9cf0202

Please sign in to comment.