[FIX] survey: prefill glitch

When user answers to multiple suggestion questions with a comment box,
the comment box was prefilled with the ID's of the suggestion instead of
user-entered data.

This commit fixes #3149 and closes #3171.
This commit is contained in:
Richard Mathot 2015-01-16 14:53:17 +01:00
parent dbb9c8ebeb
commit b117fcfbac
1 changed files with 13 additions and 2 deletions

View File

@ -84,8 +84,19 @@ $(document).ready(function () {
var prefill_def = $.ajax(prefill_controller, {dataType: "json"})
.done(function(json_data){
_.each(json_data, function(value, key){
the_form.find(".form-control[name=" + key + "]").val(value);
the_form.find("input[name^=" + key + "]").each(function(){
// prefill of text/number/date boxes
var input = the_form.find(".form-control[name=" + key + "]");
input.val(value);
// special case for comments under multiple suggestions questions
if (_.string.endsWith(key, "_comment") &&
(input.parent().hasClass("js_comments") || input.parent().hasClass("js_ck_comments"))) {
input.siblings().find('>input').attr("checked","checked");
}
// checkboxes and radios
the_form.find("input[name^=" + key + "][type!='text']").each(function(){
$(this).val(value);
});
});