smarty-php / smarty-php/smarty

Extend function "html_options"

Open
#732 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
PHP
Stars
2.3k
Forks
709
PR merge metrics
No merged PRs in 30d

Description

  1. Add parameter datalist(type: bool, default: false) to generate <datalist> if set true
  2. Add parameters placeholder_value and placeholder_output(type: string, default: null) to prepend <option value="$param['placeholder_value']" disabled>$param['placeholder_output']</option>
  3. Add parameter option_class(type: string, default: null) to set option class or pass '' to omit option class (in current version class attribute adds to optiontags too - this break styles sometimes).

and start using SimpleXMLElement or DOMElement to generate tags - no need escape attribute values and detect boolean attributes:

$doc = (new DOMImplementation())->createDocument(null, 'html');
$tag = empty($param['datalist']) ? 'select' : 'datalist';
$parent = $html->appendChild($doc->createElement($tag));
foreach ($attributes as $key => $value) {
   $parent->setAttribute($key, $value);
}
foreach ($options as $key => $value) {
   $option = $parent->appendChild($doc->createElement('option', $value));
   $option->setAttribute('value', $key);
   if (in_array($key, (array) $selected, true)) {
      $option->setAttribute('selected', '');
   }
}
return $doc->saveHTML($parent);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the existing html_options implementation and trace how it currently builds the select, attributes, and option tags. Review the requested datalist, placeholder, and option_class parameters alongside the proposed DOMElement approach. Done means the helper supports those parameters and generates correctly escaped select or datalist markup with the requested option attributes.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.