Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
7cb6fe908b |
@ -7,26 +7,16 @@ use itguild\forms\inputs\Select;
|
|||||||
|
|
||||||
class SelectBuilder
|
class SelectBuilder
|
||||||
{
|
{
|
||||||
|
|
||||||
// public static function build(string $name, array $params = [])
|
|
||||||
// {
|
|
||||||
// $value = $params['value'] ?? null;
|
|
||||||
// unset($params['value']);
|
|
||||||
// $options = $params['options'] ?? [];
|
|
||||||
// unset($params['options']);
|
|
||||||
//
|
|
||||||
// return new Select(name: $name, options: $options, value: $value, paramsArray: $params);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static function build(string $name, array $params = []): Select
|
public static function build(string $name, array $params = []): Select
|
||||||
{
|
{
|
||||||
$value = $params['value'] ?? null;
|
$value = $params['value'] ?? null;
|
||||||
unset($params['value']);
|
unset($params['value']);
|
||||||
if (isset($params['prompt'])) {
|
if (isset($params['prompt'])) {
|
||||||
$options['prompt'] = $params['prompt'] ?? null;
|
$options['prompt'] = $params['prompt'];
|
||||||
foreach ($params['options'] as $key => $val) {
|
foreach ($params['options'] as $key => $val) {
|
||||||
$options[$key] = $val;
|
$options[$key] = $val;
|
||||||
}
|
}
|
||||||
|
unset($params['prompt']);
|
||||||
} else {
|
} else {
|
||||||
$options = $params['options'] ?? [];
|
$options = $params['options'] ?? [];
|
||||||
}
|
}
|
||||||
|
@ -11,28 +11,6 @@ trait CreateOption
|
|||||||
* @param $value
|
* @param $value
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
// public function createOption(array $options, $value = null): string
|
|
||||||
// {
|
|
||||||
// $optionsString = "";
|
|
||||||
// if (is_array($value)) {
|
|
||||||
// foreach ($options as $val => $title) {
|
|
||||||
// $selected = in_array($title, $value) ? "selected" : "";
|
|
||||||
// $optionsString .= "<option $selected value='$val'>$title</option>";
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// foreach ($options as $val => $title) {
|
|
||||||
// if (is_numeric($value)) {
|
|
||||||
// $selected = (int)$value === $val ? "selected" : "";
|
|
||||||
// } else {
|
|
||||||
// $selected = $value === $val ? "selected" : "";
|
|
||||||
// }
|
|
||||||
// $optionsString .= "<option $selected value='$val'>$title</option>";
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return $optionsString;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public function createOption(array $options, $value = null): string
|
public function createOption(array $options, $value = null): string
|
||||||
{
|
{
|
||||||
$optionsString = "";
|
$optionsString = "";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user