I use the code as outlined
in this answer
for masking values with text in dropdown menus.
I would additionally like the answers to default to some string "2".
For LS 2.X there are some solutions given in the forum, like
here
.
I struggle to adapt it to my LS 3.16 installation.
I guess there is sth. that should do what I mean in the section
///Default to "2" in the following code. While it's not working, you most probably get the line of thought:
Code:
$(document).on('ready pjax:scriptcomplete',function(){
var thisQuestion = $('#question{QID}');
/// Default to "2" ----- doesn't work :P
$('.inserted-select', thisQuestion).each(function(i){
$(this).closest('.answer-item').prop('value', '2')
});
// Insert selects
$('.answer-item', thisQuestion).append('<select class="inserted-select form-control list-question-select">\
<option value="1">+</option>\
<option value="2">0</option>\
<option value="3">-</option>\
<option value="">Keine Angabe</option>\
</select>');
// Listeners
$('.inserted-select', thisQuestion).on('change', function(i) {
if($(this).val() != '') {
$(this).closest('.answer-item').find('input:text').val($.trim($('option:selected', this).text())).trigger('change');
}
else {
$(this).closest('.answer-item').find('input:text').val('').trigger('change');
}
});
// Returning to page
$('input:text', thisQuestion).each(function(i) {
var thisCell = $(this).closest('.answer-item');
var inputText = $.trim($(this).val());
var selectval = $('select.inserted-select option', thisCell).filter(function () { return $(this).html() == inputText; }).val();
$('select.inserted-select', thisCell).val(selectval);
});
// Clean-up styles
$('select.inserted-select', thisQuestion).css({
'max-width': '100%'
});
$('input:text', thisQuestion).css({
'position': 'absolute',
'left': '-9999em'
});
});
As always, I'd appreciate any help .