简体   繁体   English

<noerrorobjectavailable>闪电 web 组件 (LWC) 中的脚本错误</noerrorobjectavailable>

[英]<NoErrorObjectAvailable> Script error in lightning web component (LWC)

I am trying to create a customer review form but having issues when the user is about to submit it.我正在尝试创建客户评论表,但在用户即将提交时遇到问题。

Whenever I try to test by clicking the submit button, I keep getting the error below,每当我尝试通过单击提交按钮进行测试时,我都会收到以下错误消息,

error 错误信息的截图

Where could I have gone wrong?我哪里可能出错了?

My code can be found below (HTML, then Javascript)我的代码可以在下面找到(HTML,然后是 Javascript)

<template>
    <lightning-record-edit-form object-api-name="Customer_Review__c" onsubmit={handleSubmit} record-id={recordId}>
        <lightning-messages></lightning-messages>
        <lightning-input-field field-name="Hotel_Rating__c"></lightning-input-field>
        <lightning-input-field field-name="Price_Rating__c"></lightning-input-field>
        <lightning-input-field field-name="Staff_Rating__c"></lightning-input-field>
        <lightning-input-field field-name="Room_Rating__c"></lightning-input-field>
        <lightning-input-field field-name="Event_Rating__c"></lightning-input-field>
        <lightning-input-field field-name="Equipment_Rating__c"></lightning-input-field>
        <lightning-input-field field-name="Environment_Rating__c"></lightning-input-field>
        <lightning-input-field field-name="Manager_Rating__c"></lightning-input-field>
        <lightning-input-field field-name="Cocktail_Rating__c"></lightning-input-field>
        <lightning-input-field field-name="Drink_Rating__c"></lightning-input-field>
        <lightning-button type="submit" label="Submit Review"></lightning-button>
    </lightning-record-edit-form>
</template>
import { LightningElement, api } from 'lwc';

export default class Marriott extends LightningElement {
    @api
    handleSubmit(event) {
        // Prevent the form from being submitted
        event.preventDefault();

        // Get the form element
        const form = event.target;

        // Get the values of the form fields
        const values = {};
        for (let field of form.elements) {
            if (field.name) {
                values[field.name] = field.value;
            }
        }

        // Output the form values to the console
        console.log(values);

        // Clear the form fields
        form.reset();
    }
}

Try putting the code of handleSubmit in a try catch block and console.log the error.尝试将 handleSubmit 的代码放在 try catch 块中,并在 console.log 中记录错误。 This is helpful in debugging the NoErrorObjectAvailable error.这有助于调试 NoErrorObjectAvailable 错误。 Is handle submit being used outside the Mari.nette class. It is defined as an api method处理提交是否在 Mari.nette class 之外使用。它被定义为 api 方法

Try replacing尝试更换

const form = event.target; const form = event.target;

with

const fields = event.detail.fields常量字段 = event.detail.fields

and loop over fields instead of form.elements并循环遍历字段而不是 form.elements

Since this is supported by lightning-record-edit-form's submit event and you want to loop over the fields因为这是由 lightning-record-edit-form 的提交事件支持的,所以你想遍历这些字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LWC:如何在 Lightning Web Components(LwC) salesforce 中的图表 js 条中显示数据值 - LWC: How to display data values in chart js bars in Lightning Web Components(LwC) salesforce 输入有效的 URL 并重试: Salesforce Lightning Web 组件错误 - Enter a valid URL and try again : Salesforce Lightning Web Component Error 有没有办法从闪电 Web 组件(LWC)中的 JS 将多个(和不同的)参数传递给 Apex Controller class? - Is there a way to pass multiple (and different) parameters to an Apex Controller class from JS in Lightning Web Components (LWC)? 显示 JSON 字符串的 Lightning Web 组件不起作用 - Lightning Web Component to display JSON String is not working 如何在 lightning web 组件中创建弹出窗口 - How to create popup in lightning web component 如何在 LWC 中开玩笑测试闪电药丸 - How to jest test lightning-pills in LWC Lightning Web 组件 IF 指令是否支持多个条件? - Does Lightning Web Component IF Directive support multiple conditions? Lightning Web 组件设置动态样式未按预期工作 - Lightning Web Component setting dynamic style not working as expected 401 未经授权 REST API 中闪电 web 组件 ZA8FF6C9514C35C8563B350382 - 401 Unauthorized REST API in lightning web component salesforce 在没有顶点的闪电 web 组件上创建任务仅 javascript controller? - Create a task on a lightning web component without apex only javascript controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM