Colored buttons for mood selection
This commit is contained in:
parent
f80b909c6e
commit
a8a7637a48
2 changed files with 4 additions and 2 deletions
|
@ -8,7 +8,7 @@ hidden.insertAfter($('.dtb'));
|
|||
var checked = false;
|
||||
|
||||
$(".dtb option").unwrap().each(function() {
|
||||
var btn = $('<div data-value="' + $(this).attr("value") + '" class="dtb-btn btn-secondary"><i class="' + $(this).attr("data-icon") + '"></i> ' + $(this).text() + '</div>');
|
||||
var btn = $('<div data-style="background-color: ' + $(this).attr("data-color") + ' !important; border-color: ' + $(this).attr("data-color") + ' !important;" data-value="' + $(this).attr("value") + '" class="dtb-btn btn-secondary"><i class="' + $(this).attr("data-icon") + '"></i> ' + $(this).text() + '</div>');
|
||||
if($(this).is(':checked') && !checked) {
|
||||
btn.removeClass("btn-secondary");
|
||||
btn.addClass('btn-primary');
|
||||
|
@ -20,7 +20,9 @@ $(".dtb option").unwrap().each(function() {
|
|||
$(document).on('click', '.dtb-btn', function() {
|
||||
$('.dtb-btn').removeClass('btn-primary');
|
||||
$('.dtb-btn').addClass('btn-secondary');
|
||||
$('.dtb-btn').attr('style', "");
|
||||
$(this).removeClass('btn-secondary');
|
||||
$(this).addClass('btn-primary');
|
||||
$(this).attr('style', $(this).attr('data-style'));
|
||||
$('input[name="'+selectName+'"]').val($(this).attr("data-value"));
|
||||
});
|
|
@ -28,7 +28,7 @@
|
|||
<option value="" {% if not object.mood %}selected{% endif %}>---------</option>
|
||||
|
||||
{% for mood in request.user.mood_set.all|dictsort:"value" %}
|
||||
<option data-icon="{{ mood.icon }}" value="{{ mood.id }}" {% if object.mood == mood %}selected{% endif %}>{{ mood }}</option>
|
||||
<option data-color="{{ mood.color }}" data-icon="{{ mood.icon }}" value="{{ mood.id }}" {% if object.mood == mood %}selected{% endif %}>{{ mood }}</option>
|
||||
{% endfor %}
|
||||
|
||||
</select></td></tr>
|
||||
|
|
Loading…
Reference in a new issue