Slotted error text in a form item
const [value, setValue] = useState("");
const onChange = (detail: GoabInputOnChangeDetail) => {
setValue(detail.value);
};
const errorMessage = (
<>
<i>This is </i> slotted <b>error text</b>.
</>
);<GoabxFormItem label="First name" error={errorMessage}>
<GoabxInput onChange={onChange} value={value} name="item" error={true} />
</GoabxFormItem>form: FormGroup;
constructor(private fb: FormBuilder) {
this.form = this.fb.group({
item: [""],
});
}<goabx-form-item label="First name" [formGroup]="form">
<goabx-input name="item" formControlName="item" [error]="true"></goabx-input>
<goabx-form-item-slot slot="error">
<span>This is </span>
<i>slotted </i>
<b>error text.</b>
</goabx-form-item-slot>
</goabx-form-item>const input = document.querySelector('goa-input[name="item"]');
input.addEventListener("_change", (e) => {
console.log("Value changed:", e.detail.value);
});<goa-form-item version="2" label="First name">
<goa-input version="2" name="item" error="true"></goa-input>
<div slot="error">
<span>This is </span>
<i>slotted </i>
<b>error text.</b>
</div>
</goa-form-item>Use the error slot in a form item to display formatted error messages with custom styling like bold or italic text.
When to use
Use this pattern when:
- You need to display error messages with custom formatting
- Error text requires links, bold, or other inline styling
- Standard string-based error messages are insufficient
Considerations
- Keep error messages clear and actionable
- Use formatting sparingly to highlight key information
- Ensure error text is accessible and readable by screen readers
- The input component should also have its error prop set to true for proper styling