contributte / forms Goto Github PK
View Code? Open in Web Editor NEW:sparkles: Extra contrib to nette/forms (@nette)
Home Page: https://contributte.org/packages/contributte/forms.html
License: MIT License
:sparkles: Extra contrib to nette/forms (@nette)
Home Page: https://contributte.org/packages/contributte/forms.html
License: MIT License
Hi once again we are migration legacy project to new packages and this time we are looking at contributte form renderers as replacement for instante/bootstrap3renderer
. But at this point there are few things we would need to customize. We can make our own version but I think some of our changes could be useful for others so I have some suggestions. If you like it I can prepare PRs.
Customizable label and control columns count. At this point if is hardcoded to 3:9 but in our project we often needs to customize it. I propose to add either public properties or setter to set column counts, replace hardcoded values in $wrappers
with placeholders and replace placeholders by real values in DefaultFormRenderer::getValue
.
Current renderer always make first button without any class to btn-primary
. It does not make much sense in most of our forms so we would have to explicitly add btn-*
to all buttons. What about change it to make button primary only if it is only button in form? Or if no button in form has btn-*
class?
I do not know why some renderers do this? Is it really necessary?
$form->getElementPrototype()->setNovalidate(true);
@f3l1x what you are think about rename namespace for renderers?
From namespace Contributte\Forms\Renderers to Contributte\Forms\Rendering like in Nette/Forms?
$form->setValues([])
Split it into StandaloneFormFactory a FormFactory (Nette\App\UI\Form)
Version: dev-master
I used https://github.com/FreezyBee/DoctrineFormMapper. In DB I have null in date column. If is filled date in form date is not updated in DB (NULL persists).
Example presenter:
use FreezyBee\DoctrineFormMapper\DoctrineFormMapper;
use FreezyBee\DoctrineFormMapper\IComponentMapper;
class SomePresenter extends Presenter
{
/** @var DoctrineFormMapper @inject */
public $mapper;
/** @var EntityRepository @inject */
public $articlesRepository;
protected function createComponentForm()
{
$form = new Form;
// Column
$form->addText('name');
// ManyToOne
$form->addSelect('author')
// order items
->setOption(IComponentMapper::ITEMS_ORDER, ['age' => 'ASC'])
// filter items
->setOption(IComponentMapper::ITEMS_FILTER, ['age' => 0])
// filter items by callback
->setOption(IComponentMapper::ITEMS_FILTER, function(QueryBuilder $qb) {
$qb->andWhere('entity.age != 0')
})
// custom select label renderer
->setOption(IComponentMapper::ITEMS_TITLE, function (Author $author) {
return $author->getName() . ' - ' . $author->getAge();
});
// ManyToOne
$form->addRadioList('tags')
->setOption(IComponentMapper::ITEMS_TITLE, 'name');
// ManyToMany
$form->addMultiSelect('users')
->setOption(IComponentMapper::ITEMS_TITLE, 'username');
// ManyToMany
// btw you can define items and then ITEMS_TITLE is not required
$form->addCheckboxList('countries', 'Countries', [1 => 'CZ', 2 => 'SK']);
// A) create new entity
$article = new Article;
// B) load entity from db
$article = $this->articlesRepository->find(1);
// C) create new entity by class name - see point INFO below
$article = Article::class;
// load data from entity to form
$this->mapper->load($article, $form);
$form->onSuccess[] = function (Form $form) use ($article) {
// save (map) data from form to entity - without flush!!!
$articleEntity = $this->mapper->save($article, $form);
// INFO - if article was classname, mapper create new instance
// $articleEntity is instanceof Article
// flush data...
$em = $this->mapper->getEntityManager();
$em->persist($articleEntity)
$em->flush();
};
return $form;
}
}
Example entity:
<?php
declare(strict_types=1);
namespace App\Entities;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class TestDate
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private int $id = 0;
/**
* @ORM\Column(type="string")
*/
private string $title;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?DateTime $date;
public function getId(): int
{
return $this->id;
}
public function getTitle(): int
{
return $this->title;
}
public function getDate(): DateTime
{
return $this->date;
}
public function setTitle(string $title): void
{
$this->title = $title;
}
public function setDate(DateTime $date): void
{
$this->date = $date;
}
}
Save correct data into DB
PR: #33
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.