javascript - 向 SurveyJS 评级组件添加额外的字段
问题描述
我们想在 SurveyJS 中的 Rating-component 中添加一个额外的“N/A”和“Don't know”按钮,用于具有自定义值的 React。例如,我们有值 1-2-3-4-5 和 N/A。选择此按钮时,最终状态的值应为“N/A”。
我们尝试的是添加一个渲染后功能:
var nvtRatingAfterRender = function(question, el) {
const parent = el.getElementsByClassName("sv_q_rating")[0];
const newChild = parent.children[0].cloneNode(true);
newChild.children[0].value = -99;
newChild.getElementsByClassName("sv_q_rating_item_text")[0].innerText = "NVT";
newChild.classList.add("nvt-option");
parent.appendChild(newChild);
};
并将其添加到配置中。这会导致 React 不接受纯 HTML/JavaScript 按钮的错误:
Uncaught Error: ReactDOMInput: Mixing React and non-React radio inputs with the same `name` is not supported.
它没有添加到最后的状态中,也不可能使其“活跃”(下面我们在评级中添加了“NVT”):
另一种方法可能是复制整个 Rating 组件的 JavaScript 代码,然后添加一些额外的值(从 min 到 max 循环,还添加额外的按钮)。
向参与组件的 Rating 组件添加自定义按钮的好方法是什么?
解决方案
SurveyJS 团队的回答:
您好,
您可以将rateValues
用于此目的。这是工作示例和 JSON:{ type: "rating", name: "satisfaction", title: "How satisfied are you with the Product?", rateValues: [ 1, 2, 3, 4, 5, {value: 'anyvalue', text: "NVT"} ] }
谢谢
Andrew
SurveyJS 团队
推荐阅读
- makefile - 如何从 Makefile 中的环境变量在 URL 中设置用户名和密码
- docker - 将容器存储在路径中
- javascript - 使用 Cloud Function 在 Firestore 上写入数据突然失败
- c - Apple Hypervisor 在 MacOS Big Sur beta 11.0.1 上完全崩溃
- file - Typo3 Powermail 文件上传 上传前调整文件大小
- c++ - Robocopy - 如果我在它完成之前停止它会产生损坏的文件吗?
- sql - 检查字符串是否存在子字符串
- python - 如何检查 3 列是否相同,如果值相同,如何添加一个新列?
- r - 如何使用闪亮在交互式 html 报告中显示两个数据输出
- javascript - 电子:NodeJS 'net' 模块返回空对象