Added a formatter option to the numbers generator.

This commit is contained in:
2025-10-08 07:00:01 -07:00
parent e924b55135
commit 1ab342fc20

View File

@@ -516,9 +516,10 @@ IgniteTemplate.prototype.countries = function(placeholder = null) {
* @param {String} placeholder The placeholder option if set, it's value will be -1, this will be the text displayed. * @param {String} placeholder The placeholder option if set, it's value will be -1, this will be the text displayed.
* @param {Number} placeholderValue The value of the placeholder option if the placeholder is set. Default is -1. * @param {Number} placeholderValue The value of the placeholder option if the placeholder is set. Default is -1.
* @param {Boolean} descending Whether or not the from number if first and the to number is last. * @param {Boolean} descending Whether or not the from number if first and the to number is last.
* @param {Function} formatter Optional function to format the display value of each option.
* @returns {IgniteTemplate} This ignite template. * @returns {IgniteTemplate} This ignite template.
*/ */
IgniteTemplate.prototype.numbers = function(from = 0, to = 100, placeholder = null, placeholderValue = -1, descending = false) { IgniteTemplate.prototype.numbers = function(from = 0, to = 100, placeholder = null, placeholderValue = -1, descending = false, formatter = null) {
//Generate html and populate the template with it. //Generate html and populate the template with it.
var html = ''; var html = '';
@@ -528,11 +529,11 @@ IgniteTemplate.prototype.countries = function(placeholder = null) {
if (descending) { if (descending) {
for (var i = to; i >= from; i--) { for (var i = to; i >= from; i--) {
html += `<option value='${i}'>${i}</option>`; html += `<option value='${i}'>${(formatter? formatter(i) : i)}</option>`;
} }
} else { } else {
for (var i = from; i <= to; i++) { for (var i = from; i <= to; i++) {
html += `<option value='${i}'>${i}</option>`; html += `<option value='${i}'>${(formatter? formatter(i) : i)}</option>`;
} }
} }