- Posts: 222
- Thank you received: 10
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Initially disable the Text field $('#answer294751X1038X38277').prop('disabled', 'true').addClass('ui-state-disabled'); // Listeners on Yes/No radios to toggle the Text field $('input:radio[value="A1"]', thisQuestion).click(function(){ $('#answer294751X1038X38277').prop('disabled', '').removeClass('ui-state-disabled'); }); $('input:radio[value="A2"]', thisQuestion).click(function(){ $('#answer294751X1038X38277').prop('disabled', 'true').addClass('ui-state-disabled').val(''); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Initially disable the Text field $('#answer294751X1039X38279').prop('disabled', true); // Listener on the answer choice to toggle the Text field $('#answer294751X1039X38278SQ003').on('click', function(){ if( $(this).is(':checked') ){ $('#answer294751X1039X38279').attr('disabled', false); }else{ $('#answer294751X1039X38279').attr('disabled', true).val(''); } }); }); </script>
$('#answer294751X1039X38279').prop('readonly', true).addClass('read-only');
$('#answer294751X1039X38279').prop('readonly', false).removeClass('read-only');
textarea.read-only { opacity:0.45; filter:alpha(opacity=45); }
DenisChenu wrote: Since i create some system in SkelVanilla for such situation , no jS needed, just css (Css Class in advanced settings):
See extensions.sondages.pro/themes-and-templ...b-group-inside-group
tpartner wrote: The problem is that you are disabling the textareas. If they are disabled their value is not recorded when the form submits, so is gone when you return to the page.
Try something like this:
Code:$('#answer294751X1039X38279').prop('readonly', true).addClass('read-only');Code:$('#answer294751X1039X38279').prop('readonly', false).removeClass('read-only');
And something like this in custom.css:
Code:textarea.read-only { opacity:0.45; filter:alpha(opacity=45); }
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function() { // Add class to the text field $('#answer294751X1039X38279').prop('readonly', true).addClass('read-only'); // Listener on the answer choice to remove/add the class $('#answer294751X1039X38278SQ003').on('click', function(){ if( $(this).is(':checked') ){ $('#answer294751X1039X38279').prop('readonly', false).removeClass('read-only'); }else{ $('#answer294751X1039X38279').prop('readonly', true).addClass('read-only'); } }); }); </script>
gabrieljenik wrote: By quickly reading at your code I see the following issues:
1) You are only reacting to document ready event and not the pjax:scriptcomplete (LS v3.xx)
2) You are assuming the radio or checkboxes are not set, which is not the case when you return to the page. So in case they are set, init the text inputs properly instead of clearing them.
Cheers,
$(document).on('ready pjax:scriptcomplete',function()
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function() { // Initial state if($('#answer294751X1039X38278SQ003').is(':checked')) { $('#answer294751X1039X38279').prop('readonly', true).addClass('read-only'); } // Listener on the answer choice to remove/add the class $('#answer294751X1039X38278SQ003').on('click', function(){ if( $(this).is(':checked') ) { $('#answer294751X1039X38279').prop('readonly', false).removeClass('read-only'); } else { $('#answer294751X1039X38279').prop('readonly', true).addClass('read-only'); } }); }); </script>