Files
AgentForceTest/force-app/main/default/lwc/accountQuickCreate/accountQuickCreate.js

80 lines
2.1 KiB
JavaScript

import { LightningElement, track } from "lwc";
import { ShowToastEvent } from "lightning/platformShowToastEvent";
/**
* Account Quick Create (Standalone Inputs)
* - Standalone lightning-input fields for First Name, Last Name, and Email
* - No LDS save; exposes values and basic validation
*/
export default class AccountQuickCreate extends LightningElement {
@track message;
@track firstName = "";
@track lastName = "";
@track email = "";
get isContinueDisabled() {
// Require Last Name per standard person-name requirements; email optional here
return !this.lastName;
}
handleInputChange(event) {
const { name, value } = event.target;
if (name === "firstName") {
this.firstName = value;
} else if (name === "lastName") {
this.lastName = value;
} else if (name === "email") {
this.email = value;
}
this.message = undefined;
}
handleContinue() {
// Basic validation: enforce Last Name
if (!this.lastName) {
this.dispatchEvent(
new ShowToastEvent({
title: "Validation",
message: "Last Name is required.",
variant: "warning"
})
);
return;
}
// Email validation
if (this.email && !this.isValidEmail(this.email)) {
this.dispatchEvent(
new ShowToastEvent({
title: "Validation",
message: "Please enter a valid email address.",
variant: "warning"
})
);
return;
}
// Example: expose collected values (could dispatch custom event to parent)
const detail = {
firstName: this.firstName?.trim(),
lastName: this.lastName?.trim(),
email: this.email?.trim()
};
this.dispatchEvent(
new CustomEvent("contactinput", {
detail,
bubbles: true,
composed: true
})
);
this.message = `Captured input - First: ${detail.firstName || ""}, Last: ${detail.lastName}, Email: ${detail.email || ""}`;
}
isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
}