Can't find a way to append text from attribute to options

24 views
Skip to first unread message

svirlan...@gmail.com

unread,
May 6, 2016, 2:19:07 AM5/6/16
to select2
Hi, I can't find a way to append to my price select2 options the euro sign.

The problem is that I generate the select dynamically in a foreach.
```
foreach($selects as $select)
<div class="form-group small">
<select name="price_max" class="form-control select2 markup" data-placeholder="Price From" data-markup="{{ $select->markup }}" style="width: 100%;">
<option value=""></option>
<option value="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="150">150</option>
<option value="200">200</option>
<option value="500">500</option>
</select>
</div>
endforeach
```
At the end I need to have the euro sign to all options, even on the one I will insert.

screenshot 130

I have 2 variants until now but none is not working 100% for my case:

1. I can't get the data-markup attribute of current select

```
$(".select2.markup").select2({
tags: true,
escapeMarkup: function(m) {
debugger
return m + ' ' + $(something that return current select data-markup attribute value);
}
});
```

2. I can't get the data-markup attribute of current select and after press enter key the new value does not have the euro symbol.

```
$(".select2.markup").select2({
tags: true,
templateResult: getSelectMarkup
});

function getSelectMarkup(state)
{
return state.text + $(something that return current select data-markup attribute value);
}
```
21c47e1e-1328-11e6-938c-c26987067a17.png

svirlan...@gmail.com

unread,
May 6, 2016, 2:40:39 AM5/6/16
to select2, svirlan...@gmail.com
I have found a solution but still no get the euro sign on new entries (90% solved).

$(".select2.markup").select2({
tags: true,
templateResult: getSelectMarkup
});

function getSelectMarkup(state)
{
if (!state.id) { return state.text; }
return state.text + ' ' + $(state.element).parent().attr('data-markup');
}
Reply all
Reply to author
Forward
0 new messages