Skip to content

Commit

Permalink
Fix question preview always saying question is optional
Browse files Browse the repository at this point in the history
It isn't really optional, it just says it
  • Loading branch information
gormster committed Oct 4, 2019
1 parent 3048484 commit e2266fd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion local/teameval/amd/build/formparse.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion local/teameval/amd/src/formparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,31 @@ define(['jquery'], function($) {
}
}

function serializeObject(form) {
function fixCheckboxes(form, array) {
var unchecked = $(form).find('input[type=checkbox]:not(:checked)').map(function() { return this.name; }).get();
var output = [];
for (var i = 0; i < array.length; i++) {
var field = array[i];
if (unchecked.indexOf(field.name) !== -1) {
continue;
} else {
output.push(field);
}
}
return output;
}

function serializeObject(form, options) {
options = Object.assign({
fixCheckboxes: false
}, options);

var array = $(form).serializeArray();

if (options.fixCheckboxes) {
array = fixCheckboxes(form, array);
}

var object = {};
for (var i = 0; i < array.length; i++) {
var field = array[i];
Expand Down
2 changes: 1 addition & 1 deletion local/teameval/question/comment/amd/build/question.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion local/teameval/question/comment/amd/src/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ define(['jquery', 'local_teameval/question', 'core/templates', 'core/notificatio
demoUsers.unshift({userid: -1, name: str[1], self: true});
}

this._submissioncontext = $.extend({}, data, {
this._submissioncontext = $.extend({}, Formparse.serializeObject(form, { fixCheckboxes: true }), {
users: demoUsers,
});
this._submissioncontext.description = data.description.text;
Expand Down

0 comments on commit e2266fd

Please sign in to comment.