Example #1
0
 public function renderWithTemplate($name, $value, $label, $curent_value)
 {
     $attr = ['type' => 'radio', 'name' => $name, 'value' => $value, 'id' => null];
     $radio = new Radio($name, $attr);
     $radio->setDefault($curent_value);
     return $this->getPartialFromView($this->_radiotemplate, ['form' => $this->getForm(), 'element' => $radio, 'name' => $name, 'value' => $value, 'label' => $label]);
 }
Example #2
0
 public function testFormElementRender()
 {
     $element1 = new Text("name");
     $element1->setAttributes(array('class' => 'big-input'));
     $element2 = new Radio('radio');
     $element2->setAttributes(array('value' => 0));
     $this->assertEquals('<input type="text" id="name" name="name" class="big-input" />', $element1->render());
     $this->assertEquals('<input type="text" id="name" name="name" class="big-input" />', (string) $element1);
     $this->assertEquals('<input type="radio" id="radio" name="radio" value="0" />', (string) $element2);
 }
 public function initialize()
 {
     $type = new Radio('type', ['1' => '单选/多选', '3' => '判断']);
     $type->setLabel('题目类型');
     $type->addValidators([new PresenceOf(['message' => '题目类型必选'])]);
     $this->add($type);
     $question = new TextArea('question');
     $question->setLabel('题目');
     $question->addValidators([new PresenceOf(['message' => '题目内容必填'])]);
     $this->add($question);
 }
Example #4
0
 public function getGender()
 {
     $genders = array('male' => '男士', 'female' => '女士', 'other' => '其他');
     $radios = array();
     $user = $this->getModel();
     foreach ($genders as $value => $label) {
         $radio = new Radio('gender', array('value' => $value));
         $radio->setLabel($label);
         $radio->setDefault($user->gender);
         $radios[$value] = $radio;
     }
     return $this->gender = $radios;
 }
Example #5
0
 /**
  * @param string $name
  * @param array $options
  * @param aray $attributes
  */
 public function __construct($name, $options = null, $attributes = null)
 {
     $optionsData = !empty($options['options']) ? $options['options'] : null;
     unset($options['options']);
     if (!is_array($attributes)) {
         $attributes = [];
     }
     $options = array_merge($options, $attributes);
     parent::__construct($name, $optionsData, $options);
 }
Example #6
0
 public function getIcons()
 {
     $icons = array('reminder' => 'Reminder', 'rumor' => 'Rumor', 'warning' => 'Warning');
     $radios = array();
     $news = $this->getModel();
     foreach ($icons as $icon => $label) {
         $radio = new Radio('icon', array('value' => $icon));
         $radio->setLabel($label);
         $radio->setDefault($news->icon);
         $radios[$icon] = $radio;
     }
     return $this->radio = $radios;
 }
 function initialize($entity = null, $options = null)
 {
     $date = new Date('date_found');
     $date->setLabel('Input Date Found');
     $date->setFilters(array('striptags', 'string'));
     $this->add($date);
     /*====================== Number =====================*/
     $number = new Text('number');
     $number->setLabel('Input Number');
     $number->setFilters(array('striptags', 'string'));
     $number->addValidators(array(new PresenceOf(array('message' => 'Number is required'))));
     $this->add($number);
     /*====================== Solved =====================*/
     $isSolved = new Radio('is_solved', array('name' => 'is_solved', 'value' => '1'));
     $isSolved->setLabel('Is Solved');
     $isSolved->addValidators(array(new PresenceOf(array('message' => 'Is solved is required'))));
     $this->add($isSolved);
     $isSolved2 = new Radio('is_solved2', array('name' => 'is_solved', 'value' => '0', 'checked' => TRUE));
     $isSolved2->setLabel('Is Solved2');
     $isSolved2->addValidators(array(new PresenceOf(array('message' => 'Is solved is required'))));
     $this->add($isSolved2);
     $systemId = new Select('system_id', Systems::find(), array('using' => array('id', 'name'), 'useEmpty' => true));
     $systemId->setLabel('Select System');
     $systemId->addValidators(array(new PresenceOf(array('message' => 'System is required'))));
     if ($entity) {
         $systemId->setDefault(array($entity->system_id));
     }
     $this->add($systemId);
     $modulesId = new Select('modules_id', Modules::find(), array('using' => array('id', 'name'), 'useEmpty' => true));
     $modulesId->setLabel('Select Modules');
     $modulesId->addValidators(array(new PresenceOf(array('message' => 'Modules is required'))));
     if ($entity) {
         $modulesId->setDefault(array($entity->modules_id));
     }
     $this->add($modulesId);
     /*===== Bug =============*/
     $systemId = new Select('system_id', Systems::find(), array('using' => array('id', 'name'), 'useEmpty' => true));
     $systemId->setLabel('Select System');
     $systemId->addValidators(array(new PresenceOf(array('message' => 'System is required'))));
     if ($entity) {
         $systemId->setDefault(array($entity->system_id));
     }
     $this->add($systemId);
     $description = new TextArea('description');
     $description->setLabel('Input Description');
     $description->addValidators(array(new PresenceOf(array('message' => 'Description is required'))));
     $this->add($description);
     $hidden = new Hidden('id');
     if ($entity) {
         $hidden->setDefault(array($entity->id));
     }
     $this->add($hidden);
 }