Skip to content

Commit ed21bca

Browse files
committed
RA-2092: Form Navigator: add configuration parameter to allow empty form
1 parent 5b1eda8 commit ed21bca

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

omod/src/main/webapp/resources/scripts/navigator/navigator.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ function KeyboardController(formElement) {
5353
});
5454

5555
var confirmationSection = new ConfirmationSectionModel(
56-
$('#confirmation'),
57-
breadcrumb, _.clone(sections),
58-
formElement.hasClass('skip-confirmation-section'),
59-
navButtons);
56+
$('#confirmation'),
57+
breadcrumb, _.clone(sections),
58+
formElement.hasClass('skip-confirmation-section') || formElement.find('htmlform').hasClass('skip-confirmation-section'),
59+
formElement.hasClass('allow-empty-form') || formElement.find('htmlform').hasClass('allow-empty-form'),
60+
navButtons);
6061
sections.push(confirmationSection);
6162

6263
var questions = _.flatten( _.map(sections, function(s) { return s.questions; }), true);

omod/src/main/webapp/resources/scripts/navigator/navigatorModels.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,11 @@ SectionModel.prototype.firstInvalidQuestion = function() {
607607
}
608608

609609

610-
function ConfirmationSectionModel(elem, formMenuElem, regularSections, skipConfirmation, navButtons) {
610+
function ConfirmationSectionModel(elem, formMenuElem, regularSections, skipConfirmation, allowEmptyForm, navButtons) {
611611
SelectableModel.apply(this, [elem]);
612612
this.sections = regularSections;
613613
this.skipConfirmation = skipConfirmation ? skipConfirmation : false;
614+
this.allowEmptyForm = allowEmptyForm ? allowEmptyForm : false;
614615
this.navButtons = navButtons;
615616

616617
var title = this.element.find("span.title").first();
@@ -643,7 +644,6 @@ ConfirmationSectionModel.prototype.select = function() {
643644

644645
if (!this.skipConfirmation) {
645646
// scan through the form and confirm that at least one of the fields has a value
646-
// TODO: move all this out into a separate validator at some point? is the assumption that all forms must have data true?
647647
// TODO: makes sure this works for radio buttons and checkboxes (once we add them)
648648
var hasData = _.some(this.sections, function (section) {
649649
return _.some(section.questions, function (question) {
@@ -653,7 +653,7 @@ ConfirmationSectionModel.prototype.select = function() {
653653
})
654654
})
655655

656-
if (!hasData) {
656+
if (!hasData && !this.allowEmptyForm) {
657657
this.questions[0].confirm.disable();
658658
this.element.find(".error").show();
659659
}

omod/src/test/webapp/resources/scripts/navigatorModels.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ describe("Test for simple form models", function() {
576576
var menuElement = jasmine.createSpyObj('menu', ['append']);
577577
var navButtons = jasmine.createSpyObj('navButtons', ['hide','show']);
578578
var confirmationQuestionModel = jasmine.createSpyObj('confirmationQuestion', ['confirm', 'cancel']);
579-
var confirmationSectionModel = new ConfirmationSectionModel( confirmationQuestionModel, menuElement, null, null, navButtons);
579+
var confirmationSectionModel = new ConfirmationSectionModel( confirmationQuestionModel, menuElement, null, null, null, navButtons);
580580
confirmationSectionModel.element = jasmine.createSpyObj('element', ['addClass', 'removeClass', 'triggerHandler']);
581581
confirmationSectionModel.element.find = function () { // stub out the find method to simply remove an empty jq call
582582
return jq();

0 commit comments

Comments
 (0)