Example #1
0
 private static function addressForm($config)
 {
     $name = $config['name'];
     $form = FormControls::multipleTextInputs([['label' => 'Street address 1', 'type' => 'text', 'name' => $name . '-1'], ['label' => 'Street address 2', 'type' => 'text', 'name' => $name . '-2', 'additional-text' => 'Optional']]);
     // remove input container divs because the whole
     // form will be wrapped in the error container
     $replace = ['<div>', '</div>'];
     $form = str_replace($replace, '', $form);
     // open city state
     $form .= '<div>';
     // city field
     $form .= '<div class="usa-input-grid usa-input-grid-medium">';
     $input = FormControls::textInput(['label' => 'City', 'type' => 'text', 'name' => 'city']);
     $form .= str_replace($replace, '', $input);
     $form .= '</div>';
     // state dropdown
     $form .= '<div class="usa-input-grid usa-input-grid-small">';
     $form .= str_replace($replace, '', FormControls::stateSelect());
     $form .= '</div>';
     // close city state
     $form .= '</div>';
     // zip code
     $zip = FormControls::textInput(['label' => 'ZIP', 'type' => 'text', 'name' => 'zip', 'size' => 'medium']);
     $zip = str_replace($replace, '', $zip);
     $form .= str_replace('type="text"', 'type="text" pattern="[\\d]{5}(-[\\d]{4})?" data-grouplength="5,4" data-delimiter="-" data-politespace=""', $zip);
     return $form;
 }
 public function testUSWDSTextInputMethodChainingConvertToError()
 {
     $input = FormControls::createTextInput()->setLabel('Text input label')->setType('text')->setName('input-type-text');
     $result = $input->getHtml();
     $this->assertEquality($this->baseExpected, $result);
     $expected = '<div class="usa-input-error">' . '<label for="input-type-text" class="usa-input-error-label">Text input label</label>' . '<span id="input-type-text-input-error" class="usa-input-error-message" role="alert">Helpful error message</span>' . '<input id="input-type-text" name="input-type-text" type="text" aria-describedby="input-type-text-input-error">' . '</div>';
     $errorResult = $input->setErrorMessage('Helpful error message')->getHtml();
     $this->assertEquality($this->baseExpected, $result);
 }
Example #3
0
 private static function nameForm($config)
 {
     $label = $config['label'];
     $name = $config['name'];
     // To remove the wrapping div
     $replace = ['<div>', '</div>'];
     $title = FormControls::textInput(['label' => 'Title', 'name' => $name . '-title', 'type' => 'text', 'size' => 'tiny']);
     $form = str_replace($replace, '', $title);
     $firstName = FormControls::textInput(['label' => 'First name', 'name' => $name . '-first-name', 'type' => 'text', 'additional-text' => 'Required', 'required' => true]);
     $form .= str_replace($replace, '', $firstName);
     $middleName = FormControls::textInput(['label' => 'Middle name', 'name' => $name . '-middle-name', 'type' => 'text']);
     $form .= str_replace($replace, '', $middleName);
     $lastName = FormControls::textInput(['label' => 'Last name', 'name' => $name . '-last-name', 'type' => 'text', 'additional-text' => 'Required', 'required' => true]);
     $form .= str_replace($replace, '', $lastName);
     $suffix = FormControls::textInput(['label' => 'Suffix', 'name' => $name . '-suffix', 'type' => 'text', 'size' => 'tiny']);
     $form .= str_replace($replace, '', $suffix);
     return $form;
 }
Example #4
0
 static function build()
 {
     return FormControls::select(['label' => 'State', 'type' => 'dropdown', 'name' => 'state', 'options' => ['' => '', 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'DC' => 'District Of Columbia', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming']]);
 }
Example #5
0
 public static function build($config)
 {
     $label = $config['label'];
     $type = $config['type'];
     $action = $config['action'];
     $method = isset($config['method']) ? strtoupper($config['method']) : 'GET';
     $keywords = isset($config['keywords']) ? implode(' ', $config['keywords']) : null;
     $string = '';
     // open form
     if ($type == 'big') {
         $string .= '<form class="usa-search usa-search-big"';
     } elseif ($type == 'small') {
         $string .= '<form class="usa-search usa-search-small"';
     } else {
         $string .= '<form class="usa-search"';
     }
     $string .= 'action="' . $action . '" method="' . $method . '">';
     $string .= '<div role="search">';
     // label form
     if ($type == 'big') {
         $string .= '<label class="usa-sr-only" for="search-field-big">';
     } elseif ($type == 'medium') {
         $string .= '<label class="usa-sr-only" for="search-field">';
     } elseif ($type == 'small') {
         $string .= '<label class="usa-sr-only" for="search-field-small">';
     }
     $string .= $label . '</label>';
     // search input text box
     if ($type == 'big') {
         $string .= '<input id="search-field-big" type="search" name="search"';
     } elseif ($type == 'medium') {
         $string .= '<input id="search-field" type="search" name="search"';
     } elseif ($type == 'small') {
         $string .= '<input id="search-field-small" type="search" name="search"';
     }
     $string .= strlen($keywords) > 0 ? ' value="' . $keywords . '">' : '>';
     // search button
     $string .= '<button type="submit">';
     if ($type == 'big' || $type == 'medium') {
         $string .= '<span class="usa-search-submit-text">Search</span>';
     } elseif ($type == 'small') {
         $string .= '<span class="usa-sr-only">Search</span>';
     }
     $string .= '</button>';
     $string .= '</div>';
     $string .= '</form>';
     if (isset($config['filters'])) {
         // We need to remove the closure from the USWDS search bar
         // in order to include our filters.
         $string = str_replace('</div></form>', '', $string);
         foreach ($config['filters'] as $filter) {
             if ($filter['type'] == 'checkbox') {
                 $string .= '<div class="use-with-one-whole">';
             } else {
                 $string .= '<div class="usa-width-one-half" style="margin-right: 7px;">';
             }
             $string .= FormControls::select($filter);
             $string .= '</div>';
         }
         // replace closure
         $string .= '</div></form>';
     }
     return $string;
 }
 /**
  *
  * radio
  * 
  */
 public function testRadioUSWDSSample()
 {
     $expected = '<div>' . '<fieldset class="usa-fieldset-inputs">' . '<legend class="usa-sr-only">Historical figures 2</legend>' . '<ul class="usa-unstyled-list">' . '<li>' . '<input id="pea-soup-soup" type="radio" name="soup" value="pea-soup" checked="">' . '<label for="pea-soup-soup">Elizabeth Cady Stanton</label>' . '</li>' . '<li>' . '<input id="chicken-noodle-soup" type="radio" name="soup" value="chicken-noodle">' . '<label for="chicken-noodle-soup">Susan B. Anthony</label>' . '</li>' . '<li>' . '<input id="tomato-soup" type="radio" name="soup" value="tomato">' . '<label for="tomato-soup">Harriet Tubman</label>' . '</li>' . '</ul>' . '</fieldset>' . '</div>';
     $result = FormControls::select(['label' => 'Historical figures 2', 'type' => 'radio', 'name' => 'soup', 'options' => ['pea-soup' => 'Elizabeth Cady Stanton', 'chicken-noodle' => 'Susan B. Anthony', 'tomato' => 'Harriet Tubman'], 'selected' => ['pea-soup'], 'srOnly' => true]);
     $this->assertTrue($result == $expected, $expected . "\n\n" . $result);
 }