Commit ba7865c0 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

FieldTemplate.js: replace `%d` in `<label>` text when no children are present.

parent 11ba46c3
......@@ -144,6 +144,10 @@ var QfqNS = QfqNS || {};
$element.data(this.name, this.value);
}
});
if (n.isTextRetainable($element)) {
$element.data('element-text', $element.text());
}
});
return $deserializedTemplate;
......@@ -162,9 +166,32 @@ var QfqNS = QfqNS || {};
this.value = n.replacePlaceholder(retainedPlaceholder, value);
}
});
if (n.hasRetainedText($element)) {
$element.text(n.replacePlaceholder($element.data('element-text'), value));
}
});
};
/**
* @private
* @param $element
* @returns {*}
*/
n.isTextRetainable = function ($element) {
return $element.is("label") && $element.text().indexOf('%d') !== -1 && $element.children().length === 0;
};
/**
* @private
* @param $element
* @returns {boolean}
*/
n.hasRetainedText = function ($element) {
return $element.data('element-text') !== undefined;
};
/**
* @private
* @param targetSelector
......
......@@ -37,11 +37,11 @@
<script id="template" type="text/template">
<div class="form-inline qfq-line">
<div class="form-group">
<label for="id1_%d" class="control-label">Zeile (A-K)</label>
<label for="id1_%d" class="control-label">Zeile (A-K) %d</label>
<input id="id1_%d" type="text" class="form-control" name="name1_%d">
</div>
<div class="form-group">
<label for="id2_%d" class="control-label">Zeile (1-10)</label>
<label for="id2_%d" class="control-label">Zeile (1-10) %d</label>
<input id="id2_%d" type="text" class="form-control" name="name2_%d">
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment