0

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?

enter image description here

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>
  • did the record get saved when you clicked that button? – User6670 Feb 18 at 8:59
  • yes, first date is deleted, and others are not deleted. – Ivan S. Feb 18 at 9:12
  • so when you clicked that button record got saved with all four date as empty? – User6670 Feb 18 at 9:18
  • thank you for you reply. i need to clear all values. but only empty record is first, which value i deleted. but on front end it shows that all are empty. when i refresh page they are not empty. – Ivan S. Feb 18 at 9:30
  • can you also share the code for the button that you are pressing – User6670 Feb 18 at 10:10
0

One week of suffering, and result is: if you clear values of field in JS and make this empty field hidden - it doesn't save hidden field

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.