[英]<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,每当我尝试通过单击提交按钮进行测试时,我都会收到以下错误消息,
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.