admin管理员组文章数量:1357633
I wrote code in Validation (Advanced Configuration) to validate a Capture Information - Single Choice type. When I clicked on one of the choices I set up before and called the validate
function, I got the error:
Error executing validation "inline-vld-8ba292d8e1.js" [Error, Cannot read properties of undefined (reading 'trim')]
In my opinion, Botpress called the validation function before the input received a value, leading to this error.
Validation Code (JavaScript):
function validate(input: { value: string }): boolean {
const normalizedInput = input.value.trim().toLowerCase();
return ["buy", "rent", "offplan"].includes(normalizedInput);
}
Logs (7 items - 1 error):
[Capture] User clicked on a button, so we are skipping the cognitive extraction
Executing capture card custom validation
Error executing validation "inline-vld-8ba292d8e1.js"
[Capture] Field validation failed. Extracted: "Buy". Input: Buy
[Capture] Extraction failed (2/2 attempts)
[Capture] Prompt failed. Maximum number of retries reached.
[Capture] Prompt failed
Screenshots:
- Validation Code & Capture Information Card
- Event Debugger
- Logs
What I Tried
I modified the code as follows, but the issue persists:
const normalizedInput = input?.value?.trim().toLowerCase() || "";
If I use an Execute Code Card after the Capture Information Card, the value is already stored in a variable, and this issue does not occur. However, if the value is invalid, the user is forced to enter the information from the beginning.
Alternatively, using an Expression Card after each Capture Information Card allows validation without an undefined error, but an invalid value still forces the user to re-enter the information from the start of the node.
Related Screenshot:
- Expression Card
Does anyone have a solution to prevent Botpress from triggering the validation function before the input receives a value?
本文标签:
版权声明:本文标题:javascript - Botpress Validation Function Error: "Cannot read properties of undefined (reading 'trim')& 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743947193a2566623.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论