buli
2023-07-14 5b5c1e16deaa3a9d6d0ed1ffca390655ed103df7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { LightningElement } from 'lwc';
import { reduceErrors } from 'c/ldsUtils';
import createCity from '@salesforce/apex/PageMessagesFormControllerLwc.createCity';
 
export default class PageMessagesForm extends LightningElement {
    errors;
    cityName;
 
    handleSaveButtonClick() {
        createCity({ cityName: this.cityName })
            .then(() => {
                // Handle successful result
            })
            .catch((error) => {
                this.errors = reduceErrors(error).join(', ');
                // Optionally highlight fields errors
                this.template
                    .querySelector('lightning-input')
                    .setCustomValidity('Incorrect input');
                this.template.querySelector('lightning-input').reportValidity();
            });
    }
 
    handleInputChange(event) {
        this.cityName = event.detail.value;
    }
 
    handleCancelButtonClick() {
        this.cityName = '';
    }
 
    handleErrorButtonIconClick() {
        this.template.querySelector('c-error-popover').toggle();
    }
}