From 4aed36b29b588d16bd2ee9ee0150dd3f84b54025 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 14 Mar 2015 22:49:19 -0400 Subject: [PATCH] Api explorer - render boolean fields as yes-no select --- templates/CRM/Admin/Page/APIExplorer.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/templates/CRM/Admin/Page/APIExplorer.js b/templates/CRM/Admin/Page/APIExplorer.js index 6167b913d4..4f311128b3 100644 --- a/templates/CRM/Admin/Page/APIExplorer.js +++ b/templates/CRM/Admin/Page/APIExplorer.js @@ -243,6 +243,10 @@ } } + function isYesNo(fieldName) { + return getFieldData[fieldName] && getFieldData[fieldName].type === 16; + } + /** * Should we render a select or textfield? * @@ -251,7 +255,7 @@ * @returns boolean */ function isSelect(fieldName, operator) { - return (options[fieldName] || (getFieldData[fieldName] && getFieldData[fieldName].FKApiName)) && !_.includes(TEXT, operator); + return (isYesNo(fieldName) || options[fieldName] || (getFieldData[fieldName] && getFieldData[fieldName].FKApiName)) && !_.includes(TEXT, operator); } /** @@ -262,6 +266,9 @@ * @returns boolean */ function isMultiSelect(fieldName, operator) { + if (isYesNo(fieldName)) { + return false; + } if (_.includes(MULTI, operator)) { return true; } @@ -309,8 +316,14 @@ else if (!multiSelect && _.includes(currentVal, ',')) { $valField.val(currentVal.split(',')[0]); } + // Yes-No options + if (isYesNo(name)) { + $valField.select2({ + data: [{id: 1, text: ts('Yes')}, {id: 0, text: ts('No')}] + }); + } // Select options - if (options[name]) { + else if (options[name]) { $valField.select2({ multiple: multiSelect, data: _.map(options[name], function (value, key) { -- 2.25.1