Nastaveni checked u radio – manualni vykreslovani

jirisolc
Člen | 17
+
0
-

Ahoj,
mám manuálně vykreslovaný formulář:

<form n:name="referenceForm" class="form">
    <label n:name="name">Název: <input n:name="name"></label><br>
    <label n:name="description">Popis: <textarea n:name="description"></textarea></label><br>
    <label n:name="photos">Fotky: <input n:name="photos"></label>
    <input n:name="send" class="btn btn-default left">
    {if isset($photos)}
    {foreach $photos as $item}
        <p><img src="{$basePath}{$item->path}" width="100" alt="">
            Titulní fotka:
            <input type=radio name="selectedPhotos[]" value={$item->ID}>
            Smazat:
            <input type="checkbox" name="deletePhotos[]" value="{$item->ID}">
        </p>
    {/foreach}
{/if}
</form>
protected function createComponentReferenceForm(){
       $form = new Form;
       $form->addHidden('ID', $this->getParameter('id'));
       $form->addText('name', 'Název: ');
       $form->addTextArea('description', 'Popis: ');
       $form->addMultiUpload('photos', 'Fotky: ');
       $form->addSubmit('send', 'Odeslat');
       $form->onSuccess[] = [$this, 'referenceFormSucceded'];
       return $form;
   }

   public function referenceFormSucceded($form, $values){
       $selectedPhotos = $form->getHttpData($form::DATA_TEXT, 'selectedPhotos[]');
       $deletePhotos = $form->getHttpData($form::DATA_TEXT, 'deletePhotos[]');
       $this->referenceManager->saveReference($values, $selectedPhotos, $deletePhotos);
       $this->flashMessage("Reference ulozena");
       $this->redirect('this');
   }

a nemůžu přijít na to, jak nastavit defaultně vybraný radio button. Předem díky za pomoc :)

Editoval jirisolc (3. 10. 2017 17:17)

marek-m
Člen | 66
+
0
-
protected function createComponentReferenceForm()
{
    $form = new \Nette\Forms\Form;

    $form->addHidden('ID', $this->getParameter('id'));
    $form->addText('name', 'Název: ');
    $form->addTextArea('description', 'Popis: ');
    $form->addMultiUpload('photos', 'Fotky: ');
    $form->addSubmit('send', 'Odeslat');

    $form->addRadioList('selectedPhotos', 'Titulní fotka', array(.generovat.))
        ->setDefaultValue(.doplnit alebo presenter.);
    $form->addCheckboxList('deletePhotos', 'Smazat', array(.generovat.));

    $form->onSuccess[] = [$this, 'referenceFormSucceded'];
    return $form;
}

public function referenceFormSucceded($form, $values)
{
    \Tracy\Debugger::dump($values);
    exit();
    //vo $values budes mat data, snat ich pochopis
}
<form n:name="referenceForm" class="form">
    <label n:name="name">Název: <input n:name="name"></label><br>
    <label n:name="description">Popis: <textarea n:name="description"></textarea></label><br>
    <label n:name="photos">Fotky: <input n:name="photos"></label>
    <input n:name="send" class="btn btn-default left">

    <p n:if="isset($photos)" n:foreach="$photos as $item">
        <img src="{$basePath}{$item->path}" width="100" alt="">
        Titulní fotka:
        <input type=radio n:name="selectedPhotos:$item->id">
        Smazat:
        <input type="checkbox" n:name="deletePhotos:$item->id">
    </p>
</form>