Exemplo n.º 1
0
 public function testProvidesInputSpecificationThatIncludesValidator()
 {
     $element = new RangeElement();
     $element->setAttributes(array('inclusive' => true, 'min' => 2, 'max' => 102, 'step' => 2));
     $inputSpec = $element->getInputSpecification();
     $this->assertArrayHasKey('validators', $inputSpec);
     $this->assertInternalType('array', $inputSpec['validators']);
     $expectedClasses = array('Zend\\I18n\\Validator\\Float', 'Zend\\Validator\\GreaterThan', 'Zend\\Validator\\LessThan', 'Zend\\Validator\\Step');
     foreach ($inputSpec['validators'] as $validator) {
         $class = get_class($validator);
         $this->assertTrue(in_array($class, $expectedClasses), $class);
         switch ($class) {
             case 'Zend\\Validator\\GreaterThan':
                 $this->assertTrue($validator->getInclusive());
                 $this->assertEquals(2, $validator->getMin());
                 break;
             case 'Zend\\Validator\\LessThan':
                 $this->assertTrue($validator->getInclusive());
                 $this->assertEquals(102, $validator->getMax());
                 break;
             case 'Zend\\Validator\\Step':
                 $this->assertEquals(2, $validator->getStep());
                 break;
             default:
                 break;
         }
     }
 }
Exemplo n.º 2
0
 public function __construct()
 {
     parent::__construct();
     $this->setAttribute('method', 'POST');
     // from the form factory:
     // initially populated with a list of countries
     $countrySelect = new Element\Select('countrySelect');
     $countrySelect->setLabel('Country')->setAttribute('id', 'countrySelect')->setAttribute('placeholder', 'Please enter a country name');
     $this->add($countrySelect);
     // from the form factory:
     // initially populated with a list of cities from the 1st country on the list
     $cityName = new Element\Select('cityName');
     $cityName->setAttribute('id', 'cityName')->setLabel('City Name');
     $this->add($cityName);
     // NOTE:
     // 1. must set DOCTYPE to HTML5: <!DOCTYPE html>
     // 2. not consistently supported by all browsers
     // 3. need to run isValid() to see any results
     $range = new Element\Range('range');
     $range->setLabel('Range')->setAttributes(array('min' => '0', 'max' => '100', 'step' => '1', 'required' => 'required', 'onClick' => 'displayNumber(this.value)', 'onBlur' => 'displayNumber(this.value)', 'style' => 'width: 100px'));
     $this->add($range);
     $rangeText = new Element\Text('rangeText');
     $rangeText->setAttribute('id', 'rangeText')->setAttribute('style', 'width: 30px; background-color: gray; color: white')->setAttribute('value', 50);
     $this->add($rangeText);
     $phone = new Element\Text('phone');
     $phone->setLabel('Phone')->setAttribute('id', 'phone')->setAttribute('type', 'text')->setAttribute('pattern', '^[0-9-()]+$')->setAttribute('title', 'Phone number')->setAttribute('placeholder', 'Enter phone numbers');
     $this->add($phone);
     $required = new Element\Text('required');
     $required->setLabel('Type Something')->setAttribute('id', 'required')->setAttribute('required', 'required')->setAttribute('pattern', '[0-9A-Z ]+')->setAttribute('title', 'Must enter letters, numbers or spaces only')->setAttribute('placeholder', 'required field');
     $this->add($required);
     $citySelect = new Element\Text('citySelect');
     $citySelect->setLabel('Search City')->setAttribute('id', 'citySelect')->setAttribute('placeholder', 'Please enter a city name');
     $this->add($citySelect);
     $submit = new Element\Submit('submit');
     $submit->setAttribute('value', 'Choose');
     $this->add($submit);
 }