Login Form

#509 – bfsurvey, question, parent reset after category change

Posted in ‘BF Survey’
This is a public ticket. Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.
Friday, 09 January 2015 12:50 AEDT
omnidk
Joomla! version: 2.5.24
BF Survey version: 2.2.0

After setting a parent question and saving, all is well., but then if i come back and change the text in the question and save, the question edit view says 'changes saved' and all is well until some javascript resets the 'parent' dropdown.

I've found the function in site\media\com_bfsurvey\js\question.js which is supposed to reset the parent dropdown if the 'category' dropdown changes. This is somehow getting triggered when the text field of the question has been edited/saved/ edit page loads, then boom it's resetting the parent.

So I've commented out the function because I can't figure out the bug!

Any ideas? the function is at line 300 , and I'll past it here. Cheers :)


//ajax to update the parent list based on category selection
/*
--> commented out by omni 01.08.15 because bug resetting parent,
even when category hadn't been changed.
note - this will cause issue if ever another 'category'/survey is added..

$(document).ready(function(){
$("#bfsurvey_category_id").change(function() {
var value = $(this).val();
var id = document.getElementById("bfsurvey_question_id");

$.ajax({
type: "GET",
url: "index.php?option=com_bfsurvey&view=questions&layout=form&format=json",
data: {
'catid' : value,
'enabled' : '1',
'bfsurvey_question_id' : id.value
},
dataType: 'json',
error: function (xhr, status, error) {
if(value>0){
alert(error);
alert(status);
alert(xhr.responseText);
}else{
//reset all the options in the parent drop down
var select = document.getElementById("parent");
select.options.length = 0;
}
},
success: function(data){
//reset all the options in the parent drop down
var select = document.getElementById("parent");
select.options.length = 0;

select.options.add(new Option("Top", "0"));
//now populate the new options
var len = data.length;
for(var i=0; i<len; i++){
select.options.add(new Option(data[i]['title'], data[i]['bfsurvey_question_id']));
}

$("#parent").val('').trigger("liszt:updated");
}
});

$.ajax({
type: "GET",
url: "index.php?option=com_bfsurvey&view=questions&layout=form&format=json",
data: {
'catid' : value,
'showhide' : '1',
'enabled' : '1',
'bfsurvey_question_id' : id.value
},
dataType: 'json',
error: function (xhr, status, error) {
if(value>0){
alert(error);
alert(status);
alert(xhr.responseText);
}else{
//reset all the options in the hide question
var select2 = document.getElementById("hide_question");
select2.options.length = 0;

//reset all the options in the show question
var select3 = document.getElementById("show_question");
select3.options.length = 0;
}
},
success: function(data){
//reset all the options in the hide question
var select2 = document.getElementById("hide_question");
select2.options.length = 0;

//reset all the options in the show question
var select3 = document.getElementById("show_question");
select3.options.length = 0;

select2.options.add(new Option("PLEASE SELECT", 0));
select3.options.add(new Option("PLEASE SELECT", 0));

//now populate the new options
var len = data.length;
for(var i=0; i<len; i++){
select2.options.add(new Option(data[i]['title'], data[i]['bfsurvey_question_id']));
select3.options.add(new Option(data[i]['title'], data[i]['bfsurvey_question_id']));
}

$("#hide_question").val('').trigger("liszt:updated");
$("#show_question").val('').trigger("liszt:updated");
}
});
});

//ajax to update the options in hide question list based >0){
alert(error);
alert(status);
alert(xhr.responseText);
}else{
//reset all the options in the hide_options drop down
var select = document.getElementById("hide_options");
select.options.length = 0;
}
},
success: function(data){
//reset all the options in the hide_options drop down
var select = document.getElementById("hide_options");
select.options.length = 0;

//select.options.add(new Option("Please Select", "0"));
//now populate the new options
var len = data.length;
for(var i=0; i<len; i++){
if(data[i]['bfsurvey_question_id']==value){
if(data[i]['option1']!=''){
select.options.add(new Option(data[i]['option1'], data[i]['option1']));
}
if(data[i]['option2']!=''){
select.options.add(new Option(data[i]['option2'], data[i]['option2']));
}
if(data[i]['option3']!=''){
select.options.add(new Option(data[i]['option3'], data[i]['option3']));
}
if(data[i]['option4']!=''){
select.options.add(new Option(data[i]['option4'], data[i]['option4']));
}
if(data[i]['option5']!=''){
select.options.add(new Option(data[i]['option5'], data[i]['option5']));
}
if(data[i]['option6']!=''){
select.options.add(new Option(data[i]['option6'], data[i]['option6']));
}
if(data[i]['option7']!=''){
select.options.add(new Option(data[i]['option7'], data[i]['option7']));
}
if(data[i]['option8']!=''){
select.options.add(new Option(data[i]['option8'], data[i]['option8']));
}
if(data[i]['option9']!=''){
select.options.add(new Option(data[i]['option9'], data[i]['option9']));
}
if(data[i]['option10']!=''){
select.options.add(new Option(data[i]['option10'], data[i]['option10']));
}
if(data[i]['option11']!=''){
select.options.add(new Option(data[i]['option11'], data[i]['option11']));
}
if(data[i]['option12']!=''){
select.options.add(new Option(data[i]['option12'], data[i]['option12']));
}
if(data[i]['option13']!=''){
select.options.add(new Option(data[i]['option13'], data[i]['option13']));
}
if(data[i]['option14']!=''){
select.options.add(new Option(data[i]['option14'], data[i]['option14']));
}
if(data[i]['option15']!=''){
select.options.add(new Option(data[i]['option15'], data[i]['option15']));
}
if(data[i]['option16']!=''){
select.options.add(new Option(data[i]['option16'], data[i]['option16']));
}
if(data[i]['option17']!=''){
select.options.add(new Option(data[i]['option17'], data[i]['option17']));
}
if(data[i]['option18']!=''){
select.options.add(new Option(data[i]['option18'], data[i]['option18']));
}
if(data[i]['option19']!=''){
select.options.add(new Option(data[i]['option19'], data[i]['option19']));
}
if(data[i]['option20']!=''){
select.options.add(new Option(data[i]['option20'], data[i]['option20']));
}
}
}

$("#hide_options").val('').trigger("liszt:updated");
}
});
});
*/
 
Friday, 16 January 2015 15:06 AEDT 10'
Tim
Everything Bundle, BF Quiz Plus 3 Years, BF Survey 12 Months
This issue is fixed in v2.3.2
http://tamlynsoftware.com/download/bf-survey/bf-survey-2-3-2.html

In case you are interested in the detail, the fix was applied to /media/com_bfsurvey/js/question.js

Two lines of code were added, one to get the initial value of the parent field before the AJAX refresh
//line 343
var parentValue = select.value;

And then on line 353 when we refresh the list, we pass that value rather than null
$("#parent").val(parentValue).trigger("liszt:updated");

regards

Tim
Follow us on twitter http://twitter.com/tamlynsoftware
Sunday, 18 January 2015 19:27 AEDT
omnidk
Thanks Tim! javascript has never been my strong suit haha Appreciate your help.
 
This ticket is closed, therefore read-only. You can no longer reply to it. If you need to provide more information, please open a new ticket and mention this ticket's number.
Go to top