Coder Social home page Coder Social logo

Comments (3)

terabytesoftw avatar terabytesoftw commented on June 12, 2024 1

@Gerych1984

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.

Gerych1984 avatar Gerych1984 commented on June 12, 2024

@Gerych1984

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:

  1. Save widgetTemplates and widgetTemplate separately (first can be used in widgets.php, second in current view for change/drop to base template in current case)
  2. 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.

Gerych1984 avatar Gerych1984 commented on June 12, 2024

@Gerych1984

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.