Skip to content

Commit e2df593

Browse files
author
Dmitry Kuharenok
committed
add attributes for select options; fixes
1 parent 01d76c9 commit e2df593

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Form/Element/Select.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@ class Select extends Element
1717
protected $optionsAttributes = [];
1818
protected $multiple = false;
1919

20-
public function setOptions($options, $attributes = null)
20+
public function setOptions($options, $attributes = [])
2121
{
2222
if ($options instanceof Collection)
2323
{
2424
$options = $options->getDictionary();
2525
}
2626
$this->options = $options;
2727

28-
if ($attributes)
29-
{
30-
$this->optionsAttributes = $attributes;
31-
}
28+
$this->optionsAttributes = $attributes;
3229

3330
return $this;
3431
}

src/resources/views/default/element/select.blade.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
@foreach($attributes as $attributeName => $attributeValue) {{$attributeName}}="{{$attributeValue}}" @endforeach
77
>
88
@foreach($options as $key => $option)
9-
<option value="{{$key}}" @if (array_get($optionsAttributes, $key)) {{array_get($optionsAttributes, $key)}} @endif
10-
@if (($multiple && $value && in_array((string)$key, $value, true)) || $value === (string)$key) selected="selected" @endif>{{ $option }}</option>
9+
<option value="{{$key}}"
10+
@if($optionAttributes = array_get($optionsAttributes, $key))
11+
@foreach($optionAttributes as $optionAttributeName => $optionAttributeValue) {{$optionAttributeName}}="{{$optionAttributeValue}}" @endforeach
12+
@endif
13+
@if (($multiple && $value && in_array((string)$key, $value, true)) || $value === (string)$key) selected="selected" @endif>{{ $option }}
14+
</option>
1115
@endforeach
1216
</select>
1317
<div class="form__help">{{ $help }}</div>

0 commit comments

Comments
 (0)