Method 'delete all dates of previous date deleted' is not working. When i refresh page all dates on the same place except first date - it's deleted.
IF YOU DON'T WANT TO ANSWER, PLEASE SEND REASON IN COMMENTS. IS IT STUPID QUESTION OR DIFFICULT QUESTION?
JS
@track tripId;
@track trip;
@track ticket_date1;
@track ticket_date2;
@track ticket_date3;
@track ticket_date4;
// ------------- CONNECTED CALLBACK -----------
@wire(CurrentPageReference) pageRef;
connectedCallback() {
registerListener('sendTripId', this.handleSendTripId, this);
this.resetVars();
}
resetVars() {
this.ticket_date1 = '';
this.ticket_date2 = '';
this.ticket_date3 = '';
this.ticket_date4 = '';
}
// -------- GET TRIP ID FROM LIST ----------
handleSendTripId(tripId) {
if (tripId === null) {
this.trip = undefined;
this.tripId = undefined;
return;
}
this.tripId = tripId;
}
// ---------- GET TRIP BY ID ------------------
@wire(getTrip, {
recordId: '$tripId'
})
wiredGetActivityHistory({
data
}) {
if (data) {
this.trip = data;
this.ticket_date1 = this.trip.RUEV_Trip_Ticket_Date_1__c === undefined ? undefined : this.trip.RUEV_Trip_Ticket_Date_1__c;
this.ticket_date2 = this.trip.RUEV_Trip_Ticket_Date_2__c === undefined ? undefined : this.trip.RUEV_Trip_Ticket_Date_2__c;
this.ticket_date3 = this.trip.RUEV_Trip_Ticket_Date_3__c === undefined ? undefined : this.trip.RUEV_Trip_Ticket_Date_3__c;
this.ticket_date4 = this.trip.RUEV_Trip_Ticket_Date_4__c === undefined ? undefined : this.trip.RUEV_Trip_Ticket_Date_4__c;
}
}
// ----------------FIELD CHANGES -------
handleChange(event) {
const targetName = event.target.dataset.name;
if (targetName === 'ticket_date1') {
this.ticket_date1 = event.target.value;
if (event.target.value === null || event.target.value === '') {
this.ticket_date2 = '';
this.ticket_date3 = '';
this.ticket_date4 = '';
}
} else if (targetName === 'ticket_date2') {
this.ticket_date2 = event.target.value;
if (event.target.value === null || event.target.value === '') {
this.ticket_date3 = null;
this.ticket_date4 = null;
}
} else if (targetName === 'ticket_date3') {
this.ticket_date3 = event.target.value;
if (event.target.value === null || event.target.value === '') {
this.ticket_date4 = null;
}
} else if (targetName === 'ticket_date4') {
this.ticket_date4 = event.target.value;
}
}
HTML
<template if:true={trip}>
<lightning-record-edit-form object-api-name="RUEV_Trip__c" record-id={tripId} onsuccess={handleSuccess}>
<lightning-messages></lightning-messages>
Tickets: {ticket_date1} / {ticket_date2} / {ticket_date3} / {ticket_date4}
<div class="slds-grid slds-wrap">
<div class="slds-col slds-size_1-of-1 slds-large-size_1-of-4">
<lightning-input-field field-name="RUEV_Trip_Ticket_Date_1__c" value={ticket_date1}
data-name="ticket_date1" onchange={handleChange}>
</lightning-input-field>
</div>
<template if:true={ticket_date1}>
<div class="slds-col slds-size_1-of-1 slds-large-size_1-of-4">
<lightning-input-field field-name="RUEV_Trip_Ticket_Date_2__c" value={ticket_date2}
data-name="ticket_date2" onchange={handleChange}>
</lightning-input-field>
</div>
<template if:true={ticket_date2}>
<div class="slds-col slds-size_1-of-1 slds-large-size_1-of-4">
<lightning-input-field field-name="RUEV_Trip_Ticket_Date_3__c" value={ticket_date3}
data-name="ticket_date3" onchange={handleChange}>
</lightning-input-field>
</div>
<template if:true={ticket_date3}>
<div class="slds-col slds-size_1-of-1 slds-large-size_1-of-4">
<lightning-input-field field-name="RUEV_Trip_Ticket_Date_4__c" value={ticket_date4}
data-name="ticket_date4" onchange={handleChange}>
</lightning-input-field>
</div>
</template>
</template>
</template>
</div>
<lightning-button class="slds-m-top_small" variant="success" type="submit" name="update"
label="Update">
</lightning-button>
</lightning-record-edit-form>
</template>