Skip to content

Commit

Permalink
Merge pull request #33827 from dimagi/jls/empty-question-labels
Browse files Browse the repository at this point in the history
Removed question labels altogether when they have no content
  • Loading branch information
orangejenny committed Dec 19, 2023
2 parents 81481ab + fe0bcd5 commit 02de25b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 23 additions & 10 deletions corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ hqDefine("cloudcare/js/form_entry/form_ui", function () {
self.domain_meta = parseMeta(json.datatype, json.style);
}
self.throttle = 200;
self.setWidths();
// If the question has ever been answered, set this to true.
self.hasAnswered = false;

Expand All @@ -755,6 +754,17 @@ hqDefine("cloudcare/js/form_entry/form_ui", function () {
return (self.error() || self.serverError()) && !self.dirty();
});

self.hasLabelContent = ko.computed(function () {
return (
ko.utils.unwrapObservable(self.caption)
|| ko.utils.unwrapObservable(self.caption_markdown)
|| ko.utils.unwrapObservable(self.help)
|| ko.utils.unwrapObservable(self.hint)
|| ko.utils.unwrapObservable(self.required)
);
});
self.setWidths(self.hasLabelContent());

self.form = function () {
var parent = self.parent;
while (parent.type && parent.type() !== null) {
Expand Down Expand Up @@ -868,19 +878,22 @@ hqDefine("cloudcare/js/form_entry/form_ui", function () {
return this.stylesContaining(pattern).length > 0;
};

Question.prototype.setWidths = function () {
Question.prototype.setWidths = function (hasLabel) {
const self = this;
const columnWidth = Question.calculateColumnWidthForPerRowStyle(this.style);
const columnWidth = Question.calculateColumnWidthForPerRowStyle(self.style);
const perRowPattern = new RegExp(`\\d+${constants.PER_ROW}(\\s|$)`);

if (this.stylesContains(perRowPattern)) {
this.controlWidth = constants.FULL_WIDTH;
this.labelWidth = constants.FULL_WIDTH;
this.questionTileWidth = `col-sm-${columnWidth}`;
if (self.stylesContains(perRowPattern)) {
self.controlWidth = constants.FULL_WIDTH;
self.labelWidth = constants.FULL_WIDTH;
self.questionTileWidth = `col-sm-${columnWidth}`;
} else {
this.controlWidth = constants.CONTROL_WIDTH;
this.labelWidth = constants.LABEL_WIDTH;
this.questionTileWidth = constants.FULL_WIDTH;
self.controlWidth = constants.CONTROL_WIDTH;
self.labelWidth = constants.LABEL_WIDTH;
self.questionTileWidth = constants.FULL_WIDTH;
if (!hasLabel) {
self.controlWidth += ' ' + constants.LABEL_OFFSET;
}
}

if (self.stylesContains(constants.SHORT)) {
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/cloudcare/templates/form_entry/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ <h1 class="title" data-bind="text: title, visible: !showInFormNavigation()"></h1
on: $root.forceRequiredVisible,
}
">
<label class="caption control-label" data-bind="css: labelWidth, attr: {'for': entry.entryId}">
<label class="caption control-label" data-bind="css: labelWidth, attr: {'for': entry.entryId}, visible: hasLabelContent">
{# appearance attributes TEXT_ALIGN_CENTER TEXT_ALIGN_RIGHT #}
<div data-bind="css: {
'row': help(),
Expand Down

0 comments on commit 02de25b

Please sign in to comment.