Checkboxlist neposílá value a setRequired tudíž nefunguje

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
tttpapi
Člen | 100
+
0
-

Ahoj,

mám checkboxlist, kde si vypisuji uživatele.

<?php
{foreach $form['check_users']->items as $key => $label}
  <label title="{$label}"><input type="checkbox" name="check_users[level_1_{$key}]" value="level_1_{$key}">{$label|truncate:18:'...'}</label>
{/foreach}
?>

Jakmile ho odešlu, tak mi přijde object, který tyto hodnoty obsahuje ve value, ale pokud si vypíšu samotný value, tak mi vrací prázdné pole. Takže pokud na tento checkboxlist dám setRequired, tak to pokaždé hlásí, že ho mám prázdný…

Potřeboval bych poradit, jak ho přimět, aby mi value něco vracelo a začal mi fungovat setRequired.
Verze Nette mám 2.1.2.

Díky za pomoc.

Objekt value:

<?php
//var_dump($testPole->value);
array(0) {
}
?>

Objekt, který se mi vrátí:

<?php
//var_dump($testPole);
class Nette\Forms\Controls\CheckboxList#164 (15) {
  protected $separator =>
  class Nette\Utils\Html#175 (4) {
    private $name =>
    string(2) "br"
    private $isEmpty =>
    bool(true)
    public $attrs =>
    array(0) {
    }
    protected $children =>
    array(0) {
    }
  }
  private $items =>
  array(7) {
    [1] =>
    string(13) "Admin Adminer"
    [2] =>
    string(10) "John Smith"
    [3] =>
    string(16) "Michael Hutchins"
    [7] =>
    string(17) "Monica Stevensons"
    [11] =>
    string(11) "Petr Johnson"
    [12] =>
    string(10) "Mario Bros"
    [13] =>
    string(10) "Luigi Bros"
  }
  public $caption =>
  string(22) "Define approving users"
  protected $value =>
  array(6) {
    [0] =>
    string(9) "level_1_1"
    [1] =>
    string(9) "level_1_2"
    [2] =>
    string(10) "level_1_12"
    [3] =>
    string(9) "level_2_2"
    [4] =>
    string(9) "level_2_3"
    [5] =>
    string(10) "level_2_12"
  }
  protected $control =>
  class Nette\Utils\Html#165 (4) {
    private $name =>
    string(5) "input"
    private $isEmpty =>
    bool(true)
    public $attrs =>
    array(2) {
      'type' =>
      string(8) "checkbox"
      'name' =>
      NULL
    }
    protected $children =>
    array(0) {
    }
  }
  protected $label =>
  class Nette\Utils\Html#166 (4) {
    private $name =>
    string(5) "label"
    private $isEmpty =>
    bool(false)
    public $attrs =>
    array(0) {
    }
    protected $children =>
    array(0) {
    }
  }
  private $errors =>
  array(0) {
  }
  protected $disabled =>
  bool(false)
  private $omitted =>
  bool(false)
  private $rules =>
  class Nette\Forms\Rules#167 (5) {
    private $required =>
    NULL
    private $rules =>
    array(1) {
      [0] =>
      class Nette\Forms\Rule#176 (7) {
        ...
      }
    }
    private $parent =>
    NULL
    private $toggles =>
    array(0) {
    }
    private $control =>
          ...

  }
  private $translator =>
  bool(true)
  private $options =>
  array(0) {
  }
  private $parent =>
  class Nette\Application\UI\Form#96 (19) {
    public $onSuccess =>
    array(1) {
      [0] =>
      class Closure#212 (2) {
        ...
      }
    }
    public $onError =>
    NULL
    public $onSubmit =>
    NULL
    private $submittedBy =>
    class Nette\Forms\Controls\SubmitButton#207 (16) {
      public $onClick =>
      NULL
      public $onInvalidClick =>
      NULL
      private $validationScope =>
      NULL
      public $caption =>
      string(4) "Save"
      protected $value =>
      string(4) "Save"
      protected $control =>
      class Nette\Utils\Html#208 (4) {
        ...
      }
      protected $label =>
      class Nette\Utils\Html#209 (4) {
        ...
      }
      private $errors =>
      array(0) {
        ...
      }
      protected $disabled =>
      bool(false)
      private $omitted =>
      bool(true)
      private $rules =>
      class Nette\Forms\Rules#210 (5) {
        ...
      }
      private $translator =>
      bool(true)
      private $options =>
      array(0) {
        ...
      }
      private $parent =>
              ...

      private $name =>
      string(4) "send"
      private $monitors =>
      array(1) {
        ...
      }
    }
    private $httpData =>
    array(9) {
      'id' =>
      string(1) "0"
      'title' =>
      string(7) "gdfhgfd"
      'document_types_id' =>
      string(1) "1"
      'description' =>
      string(12) "hgfdhgfdhgfd"
      'date_valid' =>
      string(10) "31.05.2014"
      'date_end_info' =>
      string(10) "30.05.2014"
      'check_users' =>
      array(6) {
        ...
      }
      'send' =>
      string(4) "Save"
      'files' =>
      array(1) {
        ...
      }
    }
    private $element =>
    class Nette\Utils\Html#94 (4) {
      private $name =>
      string(4) "form"
      private $isEmpty =>
      bool(false)
      public $attrs =>
      array(4) {
        ...
      }
      protected $children =>
      array(0) {
        ...
      }
    }
    private $renderer =>
    NULL
    private $translator =>
    NULL
    private $groups =>
    array(0) {
    }
    private $errors =>
    array(0) {
    }
    public $httpRequest =>
    NULL
    public $onValidate =>
    NULL
    protected $currentGroup =>
    NULL
    private $validated =>
    NULL
    private $components =>
    array(14) {
      'id' =>
      class Nette\Forms\Controls\HiddenField#93 (14) {
        ...
      }
      'title' =>
      class Nette\Forms\Controls\TextInput#102 (16) {
        ...
      }
      'document_types_id' =>
      class Nette\Forms\Controls\SelectBox#109 (16) {
        ...
      }
      'date_valid' =>
      class Nette\Forms\Controls\TextInput#115 (16) {
        ...
      }
      'date_end_info' =>
      class Nette\Forms\Controls\TextInput#121 (16) {
        ...
      }
      'description' =>
      class Nette\Forms\Controls\TextArea#127 (16) {
        ...
      }
      'files' =>
      class Nette\Forms\Controls\UploadControl#132 (13) {
        ...
      }
      'categories_id' =>
      class Nette\Forms\Controls\CheckboxList#140 (15) {
        ...
      }
      'tags_id' =>
      class Nette\Forms\Controls\CheckboxList#149 (15) {
        ...
      }
      'direct_release' =>
      class Nette\Forms\Controls\Checkbox#156 (14) {
        ...
      }
      'check_users' =>
              ...

      'info_users' =>
      class Nette\Forms\Controls\CheckboxList#182 (15) {
        ...
      }
      'info_departments' =>
      class Nette\Forms\Controls\CheckboxList#197 (15) {
        ...
      }
      'send' =>
      class Nette\Forms\Controls\SubmitButton#207 (16) {
        ...
      }
    }
    private $cloning =>
    NULL
    private $parent =>
    class DocumentForm#81 (19) {
      private $form =>
              ...

      private $database =>
      class Nette\Database\Context#63 (4) {
        ...
      }
      private $baseModel =>
      class App\Model\BaseModel#83 (1) {
        ...
      }
      private $documentsModel =>
      class App\Model\Documents#87 (1) {
        ...
      }
      private $categoriesModel =>
      class App\Model\Categories#88 (1) {
        ...
      }
      private $tagsModel =>
      class App\Model\Tags#89 (1) {
        ...
      }
      private $usersModel =>
      class App\Model\Users#91 (1) {
        ...
      }
      private $departmentsModel =>
      class App\Model\Departments#92 (1) {
        ...
      }
      private $id =>
      int(0)
      private $valid_extensions =>
      array(3) {
        ...
      }
      private $template =>
      NULL
      private $invalidSnippets =>
      array(0) {
        ...
      }
      public $snippetMode =>
      NULL
      protected $params =>
      array(0) {
        ...
      }
      private $components =>
      array(1) {
        ...
      }
      private $cloning =>
      NULL
      private $parent =>
      class App\Presenters\DocumentsPresenter#62 (40) {
        ...
      }
      private $name =>
      string(12) "documentForm"
      private $monitors =>
      array(1) {
        ...
      }
    }
    private $name =>
    string(12) "documentForm"
    private $monitors =>
    array(2) {
      'Nette\Forms\Form' =>
      array(4) {
        ...
      }
      'Nette\Application\UI\Presenter' =>
      array(4) {
        ...
      }
    }
  }
  private $name =>
  string(11) "check_users"
  private $monitors =>
  array(1) {
    'Nette\Forms\Form' =>
    array(4) {
      [0] =>
      class Nette\Application\UI\Form#96 (19) {
        ...
      }
      [1] =>
      int(1)
      [2] =>
      string(11) "check_users"
      [3] =>
      bool(true)
    }
  }
}
?>

Editoval tttpapi (28. 5. 2014 9:32)

Čamo
Člen | 798
+
0
-

Input type checkbox nikdy neposiela value. Taký atribút u checkboxov nieje. U checkboxov sa zisťuje iba či je zaškrtnutý, alebo nie. Na server sa posielajú iba tie checkboxy, ktoré sú zaškrtnuté. A setrequired i nich funguje.

tttpapi
Člen | 100
+
0
-

Takto mám vytvořen checkboxlist a pokud je checkbox direct release nezaškrtnut, tak se provede kontrola.

<?php
$this->form->addCheckboxList('check_users', 'label',
$this->baseModel->dbResultToArray($this->usersModel->getUsers(), 'first_name,last_name'))
->addConditionOn($this->form['direct_release'], Nette\Forms\Form::EQUAL, FALSE)
->setRequired();
?>

A i když zaškrtnu 1 a více checkboxů z listu, tak se mi stejně vrátí chyba, že prvek nemůže být empty.

David Matějka
Moderator | 6445
+
0
-

Jelikoz ti neodpovidaji klice.
Definujes polozky s klicema 1, 2, 3… A Rucne vykreslujes s klicema level1_1, level2_3, …