Comments (3)
Your suggestion #157 of template for each widget from the factory, thinking about it makes sense but we can simplify it, without affecting the widgets, which you think is this way of doing it:
FieldAttributes.php
trait FieldAttributes
{
private array $widgetTemplate = [];
private function setWidgetTemplate(string $widgetClass): self
{
$new = clone $this;
$new->template = $new->widgetTemplate[$widgetClass] ?? $new->template;
return $new;
}
}
Field::php
final class Field extends Widget
{
public function checkboxList(array $attributes = [], array $items = [], array $itemsFromValues = []): self
{
$new = clone $this;
$new->setWidgetTemplate(CheckboxList::class);
}
}
Example config:
Field::class => [
'template()' => [
'{label}<div class="col-sm-10">{input}{error}</div>'
],
'widgetTemplate()' =>[
[
CheckboxList::class => 'your template' // set your custom templete here
],
],
],
This should work without adding anything to each widget and without creating another widget.
from form.
Your suggestion #157 of template for each widget from the factory, thinking about it makes sense but we can simplify it, without affecting the widgets, which you think is this way of doing it:
FieldAttributes.php
trait FieldAttributes { private array $widgetTemplate = []; private function setWidgetTemplate(string $widgetClass): self { $new = clone $this; $new->template = $new->widgetTemplate[$widgetClass] ?? $new->template; return $new; } }
Field::php
final class Field extends Widget { public function checkboxList(array $attributes = [], array $items = [], array $itemsFromValues = []): self { $new = clone $this; $new->setWidgetTemplate(CheckboxList::class); } }
Example config:
Field::class => [ 'template()' => [ '{label}<div class="col-sm-10">{input}{error}</div>' ], 'widgetTemplate()' =>[ [ CheckboxList::class => 'your template' // set your custom templete here ], ], ],
This should work without adding anything to each widget and without creating another widget.
My PR not pretended for last instance and can be improved. But few propose:
- Save
widgetTemplates
andwidgetTemplate
separately (first can be used in widgets.php, second in current view for change/drop to base template in current case) - I think
setCurrentWidget
not works with that implementation. They should return string or pass current instance as argument. Another inner$new
do nothing
from form.
Your suggestion
And I it's are PR, with already works code, tests and phpdoc. Not issue or suggest. Little issue I will write on remark
from form.
Related Issues (20)
- Code style - chain calls HOT 15
- Add `$content` parameter to `Field::*Button()` methods
- Yiisoft\Validator\DataSet\AttributeDataSet not found
- Dependency update/adjust to yiisoft/html HOT 2
- Nested array form with translations HOT 3
- Checkbox don't accept label parameters HOT 1
- Input field name array HOT 1
- Add php attribute like #[SkipHydration] to skip private properties in collectAttributes() HOT 1
- Naming issue: attribute HOT 1
- Allow use fields without form model HOT 1
- Add constant with default theme and theme parameter to `Field` helper HOT 1
- Make fields indepent from validator HOT 1
- Raise PHP version to 8.1 HOT 1
- Add theme for Bootstap 5 HOT 1
- Checkbox 'checked' parameter input HOT 20
- Add ability partly change theme in `PureFieldFactory`
- Remove scrutinizer
- Change minimum stability in composer.json to stable
- Add method in fields for set closure that prepare value for field
- update irc link
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from form.