Bootstrap 3 pro jeden, nebo všechny formuláře – návod (Instante/Bootstap3Renderer)
- ludek
- Člen | 83
1. nainstalovat doplněk Instante/Bootstap3Renderer (https://bitbucket.org/…rap3renderer)
info: https://forum.nette.org/…ni-formulare#…
composer require instante/bootstrap-3-renderer:@dev
2.A Pro jednotlivý formulář: jen nastavíme renderer
use Instante; //<< použít namespace
class HomepagePresenter extends BasePresenter {
protected function createComponentPolozkaForm() { // továrna formuláře
$form = new UI\Form;
$form->addText('cislo', 'Číslo:', 12, 12)->addRule(Form::FILLED, 'Zadejte prosím číslo.');
//...
$form->setRenderer(new Instante\Bootstrap3Renderer\BootstrapRenderer); //<< nastavit renderer
return $form;
}
}
2.B Pro VŠECHNY formuláře: do BasePresenteru přidáme náhradní metodu a tu budeme používat v továrničkách formulářů
use Instante; //<< použít namespace
abstract class BasePresenter extends Nette\Application\UI\Presenter {
/**
* Změna vykreslování formulářů na Bootstrap 3
* @return \Nette\Application\UI\Form
*/
protected function form() {
$form = new \Nette\Application\UI\Form;
$form->setRenderer(new Instante\Bootstrap3Renderer\BootstrapRenderer);
return $form;
}
}
A v presenteru s továrničkou formuláře:
class HomepagePresenter extends BasePresenter {
protected function createComponentPolozkaForm() { //
// $form = new \Nette\Application\UI\Form;
$form = $this->form(); //<< změna
$form->addText('cislo', 'Číslo:', 12, 12)->addRule(Form::FILLED, 'Zadejte prosím číslo.');
//...
return $form;
}
}
3. V šabloně jen
{control polozkaForm}
Za doplněk díky autorům: Filip Procházka, Pavel Ptacek, Richard Ejem, Ondrej Hubsch.
Editoval ludek (7. 9. 2015 11:59)
- iguana007
- Člen | 970
blaztar napsal(a):
Má to fungovat na nejnovějším nette? Nejde mi to přes composer nainstalovat. Nějaké kolize.
Před měsícem to šlo. Díky..
Vycházel bych z tohoto:
https://github.com/…endering.php
- blaztar
- Člen | 93
C:\xampp\htdocs\test-nette>composer require instante/bootstrap-3-renderer:@dev
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- nette/nette v2.2.9 requires nette/application 2.2.6 -> no matching package found.
- nette/nette v2.2.8 requires nette/application 2.2.5 -> no matching package found.
- nette/nette v2.2.7 requires nette/application 2.2.4 -> no matching package found.
- nette/nette v2.2.6 requires nette/application 2.2.3 -> no matching package found.
- nette/nette v2.2.5 requires nette/application 2.2.3 -> no matching package found.
- nette/nette v2.2.4 requires nette/application 2.2.3 -> no matching package found.
- nette/nette v2.2.3 requires nette/application 2.2.2 -> no matching package found.
- nette/nette v2.2.2 requires nette/application 2.2.1 -> no matching package found.
- nette/nette v2.2.11 requires nette/application 2.2.8 -> no matching package found.
- nette/nette v2.2.10 requires nette/application 2.2.7 -> no matching package found.
- nette/nette v2.2.1 requires nette/application 2.2.0 -> no matching package found.
- nette/nette v2.2.0 requires nette/application 2.2.0 -> no matching package found.
- Conclusion: remove nette/application v2.3.5
- Conclusion: don't install nette/application v2.3.5
- nette/nette v2.3.0 requires nette/application 2.3.1 -> satisfiable by nette/application[v2.3.1].
- nette/nette v2.3.1 requires nette/application 2.3.2 -> satisfiable by nette/application[v2.3.2].
- nette/nette v2.3.2 requires nette/application 2.3.3 -> satisfiable by nette/application[v2.3.3].
- nette/nette v2.3.3 requires nette/application 2.3.3 -> satisfiable by nette/application[v2.3.3].
- nette/nette v2.3.4 requires nette/application 2.3.4 -> satisfiable by nette/application[v2.3.4].
- Can only install one of: nette/application[v2.3.1, v2.3.5].
- Can only install one of: nette/application[v2.3.2, v2.3.5].
- Can only install one of: nette/application[v2.3.3, v2.3.5].
- Can only install one of: nette/application[v2.3.4, v2.3.5].
- nette/nette v2.1.0 conflicts with nette/application[v2.3.5].
- nette/nette v2.1.1 conflicts with nette/application[v2.3.5].
- nette/nette v2.1.10 conflicts with nette/application[v2.3.5].
- nette/nette v2.1.11 conflicts with nette/application[v2.3.5].
- nette/nette v2.1.2 conflicts with nette/application[v2.3.5].
- nette/nette v2.1.3 conflicts with nette/application[v2.3.5].
- nette/nette v2.1.4 conflicts with nette/application[v2.3.5].
- nette/nette v2.1.5 conflicts with nette/application[v2.3.5].
- nette/nette v2.1.6 conflicts with nette/application[v2.3.5].
- nette/nette v2.1.7 conflicts with nette/application[v2.3.5].
- nette/nette v2.1.8 conflicts with nette/application[v2.3.5].
- nette/nette v2.1.9 conflicts with nette/application[v2.3.5].
- Installation request for nette/application == 2.3.5.0 -> satisfiable by nette/application[v2.3.5].
- instante/bootstrap-3-renderer v1.0.1 requires nette/nette ~2.1 -> satisfiable by nette/nette[v2.1.10, v2.1.11, v2.1.9, v2.1.0, v2.1.1, v2.1.2, v2.1.3, v2.1.4, v2.1.5, v2.1.6, v2.1.7, v2.1.8, v2.2.0, v2.2.1, v2.2.10, v2.2.11, v2.2.2, v2.2.3, v2.2.4, v2.2.5, v2.2.6, v2.2.7, v2.2.8, v2.2.9, v2.3.0, v2.3.1, v2.3.2, v2.3.3, v2.3.4, v2.3.5].
- instante/bootstrap-3-renderer v1.0.0 requires nette/nette ~2.1 -> satisfiable by nette/nette[v2.1.10, v2.1.11, v2.1.9, v2.1.0, v2.1.1, v2.1.2, v2.1.3, v2.1.4, v2.1.5, v2.1.6, v2.1.7, v2.1.8, v2.2.0, v2.2.1, v2.2.10, v2.2.11, v2.2.2, v2.2.3, v2.2.4, v2.2.5, v2.2.6, v2.2.7, v2.2.8, v2.2.9, v2.3.0, v2.3.1, v2.3.2, v2.3.3, v2.3.4, v2.3.5].
- instante/bootstrap-3-renderer dev-master requires nette/nette ~2.1 -> satisfiable by nette/nette[v2.1.10, v2.1.11, v2.1.9, v2.1.0, v2.1.1, v2.1.2, v2.1.3, v2.1.4, v2.1.5, v2.1.6, v2.1.7, v2.1.8, v2.2.0, v2.2.1, v2.2.10, v2.2.11, v2.2.2, v2.2.3, v2.2.4, v2.2.5, v2.2.6, v2.2.7, v2.2.8, v2.2.9, v2.3.0, v2.3.1, v2.3.2, v2.3.3, v2.3.4, v2.3.5].
- instante/bootstrap-3-renderer dev-develop requires nette/nette ~2.1 -> satisfiable by nette/nette[v2.1.10, v2.1.11, v2.1.9, v2.1.0, v2.1.1, v2.1.2, v2.1.3, v2.1.4, v2.1.5, v2.1.6, v2.1.7, v2.1.8, v2.2.0, v2.2.1, v2.2.10, v2.2.11, v2.2.2, v2.2.3, v2.2.4, v2.2.5, v2.2.6, v2.2.7, v2.2.8, v2.2.9, v2.3.0, v2.3.1, v2.3.2, v2.3.3, v2.3.4, v2.3.5].
- Conclusion: don't install nette/nette v2.3.5|install nette/nette v2.1.10|install nette/nette v2.1.11|install nette/nette v2.1.9|install nette/nette v2.1.0|install nette/nette v2.1.1|install nette/nette v2.1.2|install nette/nette v2.1.3|install nette/nette v2.1.4|install nette/nette v2.1.5|install nette/nette v2.1.6|install nette/nette v2.1.7|install nette/nette v2.1.8|install nette/nette v2.3.0|install nette/nette v2.3.1|install nette/nette v2.3.2|install nette/nette v2.3.3|install nette/nette v2.3.4
- Installation request for instante/bootstrap-3-renderer @dev -> satisfiable by instante/bootstrap-3-renderer[dev-develop, dev-master, v1.0.0, v1.0.1].
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Installation failed, reverting ./composer.json to its original content.
- David Matějka
- Moderator | 6445
divny.. ukaz jeste tvuj composer.json a zkus spustit composer self-update, jestli tam neni nejaka chyba
- blaztar
- Člen | 93
Toto bylo puštěné na nově staženém nette sandbox. Můžeš zkusit sám
:)
Jinak jakmile to mám na starším projektu a davám composer update tak se mi
nenatahují nejnovější nette balíčky jako nette database 2.3.6 apod..
{
"name": "nette/sandbox",
"description": "The sandbox is a pre-packaged Nette Framework project, basic configured structure for your application.",
"homepage": "http://nette.org",
"type": "project",
"license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"],
"authors": [
{
"name": "David Grudl",
"homepage": "http://davidgrudl.com"
},
{
"name": "Nette Community",
"homepage": "http://nette.org/contributors"
}
],
"require": {
"php": ">= 5.3.7",
"nette/application": "~2.3.0",
"nette/bootstrap": "~2.3.0",
"nette/caching": "~2.3.0",
"nette/database": "~2.3.0",
"nette/di": "~2.3.0",
"nette/finder": "~2.3.0",
"nette/forms": "~2.3.0",
"nette/http": "~2.3.0",
"nette/mail": "~2.3.0",
"nette/robot-loader": "~2.3.0",
"nette/safe-stream": "~2.3.0",
"nette/security": "~2.3.0",
"nette/utils": "~2.3.0",
"latte/latte": "~2.3.0",
"tracy/tracy": "~2.3.0",
"dg/adminer-custom": "~1.6"
},
"require-dev": {
"nette/tester": "~1.3"
}
}
- David Matějka
- Moderator | 6445
Aha, je to tim, ze nektere balicky maji vydanou novou verzi, ale neni verze nette/nette, ktere by tuto verzi balicku vyzadovalo. A ten renderer balicek ma zavislost prave na nette/nette.
Jsou dve moznosti:
1. pridat rucne do composer.json
"require": {
......,
"nette/nette": "~2.3.0",
"instante/bootstrap-3-renderer": "@dev"
}
a spustit composer update. To stahne posledni nette/nette a downgraduje balicky.
2. pridat sekci replace
"replace": {
"nette/nette": "2.3.5"
}
(musi tam byt asi presna verze, nejakou *
se mi tam nepovedlo
dat)
Tim composeru reknes, ze tvuj balicek nahrazuje nette/nette. Tim padem bude
renderer spokojen a vse se nainstaluje a ani nedojde k downgrade samotnych
nette balicku
- potapnik
- Člen | 127
Jaky je rozdíl mezi tímhle a nextras/forms kde je taky Bs3Renderer? Navíc se mi moc nelíbí mít ty formuláře přímo v presenteru, stejně člověk nakonec dospěje k tomu, že má BaseForm a nad tím extended Forms zaregistrovaný jako služby a čistej presenter :-) a v rámci toho BaseFormu tam nastaví ten renderer :-)
Editoval potapnik (6. 10. 2015 13:24)
- Šaman
- Člen | 2658
Taky mě to trklo, ale tohle vlákno není o tom, jak dostat renderer do
formulářů, tak jsem na to nereagoval.
Ale ani BaseForm není ideální řešení. Nejlepší je podle mě primitivní
tovární třída
<?php
namespace App\Model\Data;
use Nette\Application\UI\Form;
use Nette\Forms\IFormRenderer;
class FormFactory
{
/** @var IFormRenderer */
protected $renderer;
public function __construct(IFormRenderer $renderer = NULL)
{
$this->renderer = $renderer;
}
/**
* @return Form
*/
public function create()
{
$form = new Form;
$form->setRenderer($this->renderer);
return $form;
}
}
?>
kterou pak injectnu do každé tovární třídy na konkrétní formulář. Mimochodem ten renderer není nastavený natvrdo, vezme se ten, který je vytvořený v configu a funguje to i bez něj. Univerzální řešení.
Editoval Šaman (6. 10. 2015 17:39)