Exemple #1
0
    /**
     * dijit.form.RadioButton
     *
     * @param  string $id
     * @param  string $value
     * @param  array $params  Parameters to use for dijit creation
     * @param  array $attribs HTML attributes
     * @param  array $options Array of radio options
     * @param  string $listsep String with which to separate options
     * @return string
     */
    public function __invoke(
        $id = null,
        $value = null,
        array $params = array(),
        array $attribs = array(),
        array $options = null,
        $listsep = "<br />\n"
    ) {
        $attribs['name'] = $id;
        if (!array_key_exists('id', $attribs)) {
            $attribs['id'] = $id;
        }
        $attribs = $this->_prepareDijit($attribs, $params, 'element');

        if (is_array($options) && $this->_useProgrammatic() && !$this->_useProgrammaticNoScript()) {
            $baseId = $id;
            if (array_key_exists('id', $attribs)) {
                $baseId = $attribs['id'];
            }
            $filter = new AlnumFilter();
            foreach (array_keys($options) as $key) {
                $optId = $baseId . '-' . $filter->filter($key);
                $this->_createDijit($this->_dijit, $optId, array());
            }
        }

        return $this->view->formRadio($id, $value, $attribs, $options, $listsep);
    }
Exemple #2
0
    /**
     * Returns true if and only if $value contains only alphabetic and digit characters
     *
     * @param  string $value
     * @return boolean
     */
    public function isValid($value)
    {
        if (!is_string($value) && !is_int($value) && !is_float($value)) {
            $this->_error(self::INVALID);
            return false;
        }

        $this->_setValue($value);

        if ('' === $value) {
            $this->_error(self::STRING_EMPTY);
            return false;
        }

        if (null === self::$_filter) {
            self::$_filter = new \Zend\Filter\Alnum();
        }

        self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;

        if ($value != self::$_filter->filter($value)) {
            $this->_error(self::NOT_ALNUM);
            return false;
        }

        return true;
    }
 public function testRadioLabelContainsForAttributeTag()
 {
     $options = array('foo bar' => 'Foo', 'bar baz' => 'Bar', 'baz' => 'Baz');
     $html = $this->helper->__invoke(array('name' => 'foo[bar]', 'value' => 'bar', 'options' => $options));
     $filter = new Filter\Alnum();
     foreach ($options as $key => $value) {
         $id = 'foo-bar-' . $filter->filter($key);
         $this->assertRegexp('/<label([^>]*)(for="' . $id . '")/', $html);
     }
 }