Snippety a jejich magie :)
- MW
- Člen | 626
Zdravím a prosím o nakopnutí…
Mám takový form v edit.latte v TABech (záložky od Jquery – nevim,
jestli to nemůže miv vliv):
<div role="tabpanel" class="tab-pane" id="tabs-3">
<button type="button" class="btn btn-primary btn-xs" data-toggle="collapse" data-target="#unexposed">
<span class="glyphicon glyphicon-plus"></span> Nový záznam
</button>
<div id="unexposed" class="collapse">
{snippet detailForm}
<script type="text/javascript" src="{$basePath}/js/tiny_mce/tinymce.min.js"></script>
<script type="text/javascript" src="{$basePath}/js/tiny_mce/tinymce.config.js"></script>
<h2>Nová poznámka</h2>
<div style="float: left; display: block;">
{form contractsDetailForm class => 'form-horizontal ajax', role => 'form'}
<div class="form-group">
{label detailid class => "col-sm-2 control-label" /}
<div class="col-sm-10">
{input detailid class => "form-control"}
</div>
</div>
<div class="form-group">
{label contracts_id class => "col-sm-2 control-label" /}
<div class="col-sm-10">
{input contracts_id class => "form-control"}
</div>
</div>
<div class="form-group">
{label title class => "col-sm-2 control-label" /}
<div class="col-sm-10">
{input title class => "form-control"}
</div>
</div>
<div class="form-group">
{label detail class => "col-sm-2 control-label" /}
<div class="col-sm-10">
{input detail class => "form-control mce"}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10 noprint">
{input save class => "btn btn-success"}
</div>
</div>
{/form contractsDetailForm}
</div>
{if $show == TRUE}
<script type="text/javascript">
$('#unexposed').collapse('show');
</script>
{else}
<script type="text/javascript">
$('#unexposed').collapse('hide');
</script>
{/if}
<script type="text/javascript">
$('html, body').animate({ scrollTop: 0}, 'slow');
</script>
{/snippet}
</div>
A v presenteru to obsluhuju nasledovne_:
function createComponentContractsDetailForm($name) {
$form = new Form($this, $name);
$form->addHidden('detailid')->setValue($this->getParameter('detailid'));
$form->addHidden('contracts_id')->setValue($this->getParameter('id'));
$form->addText('title', 'Název:', 50)
->setRequired('Zadejte popis!');
$form->addTextArea('detail', 'Poznámka:')
->setRequired('Zadejte obsah');
if (!empty($this->detailid)) {
$detail = $this->contractsModel->getDetailById($this->detailid);
if (!$detail) {
throw new Nette\Application\BadRequestException;
}
$form->setDefaults($detail->toArray());
}
$form->addSubmit('save', 'Uložit');
$form->getComponent('save')->getControlPrototype()->onclick('tinymce.triggerSave()');
$form->onSuccess[] = callback($this, 'formDetailSubmitted');
}
function formDetailSubmitted($form) {
$values = $form->values;
$this->contractsModel->saveDetail($values, $this->user->id);
$this->detailid = NULL;
$this->show = FALSE;
$form->setValues(array(), TRUE);
$this->redrawControl();
}
mám tam i nějaký handle :
function handleDeleteDetail($detailid) {
$this->contractsModel->deleteDetail($detailid);
$this->detailid = NULL;
$this->redrawControl();
}
Tak nejak vse funguje.. jen nechapu proc musim pouzit redrawConrol bez parametru, protože jinak se neprekresli a pak se me deje pouze v IE, ze po odeslání formu se hezky vyprázdní, tedy se invaliduje, ale do inputů nelze nic psát.. pomuze bud refresh stránky a nebo kliknou na odeslat, vyskočí validace "Zadejte … " a pak to jde…
Netušíte prosím kde hledat problém ?
- Pavel Kravčík
- Člen | 1196
Většinou stačí ty JS funkce zaregistrovat do Nette.ajax.
<script>
$.nette.ext('dochazka', {
load: function (){
clovekSkript();
}
});
</script>
- MW
- Člen | 626
Asi by me stacilo nejak navesit opetovne validaci na form?
Mimochodem to dela i bez tynyMCE.. i samotny input text .. tedy proto si
rikam, ze ta validace to nejak prostouchne…
A redrawControl vůbec zde nejak nepobiram.. a to me to jinde normalne funguje a často spippety pouzivam..jen tady musí „něco“ byt :/