I am trying to resolve 2 issues with an LWC
- Render a calculated value in an LWC after the user inputs. After the calculation, render value on correct row. I can see the calculated value in console but never renders in html
- Format for:each value. I am only returning a single field value. Right now it renders the value but cannot show label. I would like the formatting to be similar to what I see using lightning-input
HTML
<template if:true={laborTypeSpecific}>
<lightning-layout-item size="12" large-device-size="2" padding="around-small">
<lightning-input name="Days_Per_Crew__c" label="Days per Crew" type="number" value={row.Days_Per_Crew__c} onchange={handleDaysPerCrewChange} required></lightning-input>
</lightning-layout-item>
<lightning-layout-item size="12" large-device-size="2" padding="around-small">
<lightning-input name="Number_of_Crew_Members__c" label="Number Of Crew Members" type="number" value={row.Number_of_Crew_Members__c} onchange={handleNumberOfCrewMembersChange} required></lightning-input>
</lightning-layout-item>
<lightning-layout-item>
<template for:each={hourlyRate} for:item="hr">
<lightning-layout-item size="12" large-device-size="2" padding="around-small" key={hr.id}>
<div class="titleheadings">Hourly Rate</div>
<span>{hr.Hourly_Rate__c}</span>
</lightning-layout-item>
</template>
</lightning-layout-item>
<lightning-layout-item size="12" large-device-size="2" padding="around-small">
<lightning-input name="Labor_Total_Calculated__c" label="Labor Total" type="number" value={row.Labor_Total_Calculated__c}></lightning-input>
</lightning-layout-item>
</template>
JS
@api row;
@api projectid;
@track hourlyRate;
laborTypeSpecific;
laborTypeOptions = [];
@wire(getObjectInfo, { objectApiName: ESTIMATE_ITEM_OBJECT })
objectInfo;
@wire(getPicklistValues, {
recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName: COST_TYPE_FIELD })
laborTypeOptionsWrapper({ data }) {
if (data) {
this.laborTypeOptions = data.values;
}
}
connectedCallback() {
getProjectHourlyrate({ paramProjectId : this.projectid })
.then(result => {
this.hourlyRate = result;
this.error = undefined;
})
.catch(error => {
this.error = error;
this.hourlyRate = undefined;
})
}
addNewRow() {
const event = new CustomEvent('addrow');
this.dispatchEvent(event);
}
removeRow() {
const event = new CustomEvent('removerow', {
detail: this.row.id
});
this.dispatchEvent(event);
}
handleLaborChange(event) {
this.row.Cost_Type__c = event.detail.value;
this.laborTypeSpecific = this.row.Cost_Type__c == 'Labor - Standard' || this.row.Cost_Type__c == 'Labor - Overtime';
}
handleCostTypeChange(event) {
this.row.Cost_Type__c = event.detail.value;
}
handleDaysPerCrewChange(event) {
this.row.Days_Per_Crew__c = event.detail.value;
let numberOfCrew = this.row.Number_of_Crew_Members__c != undefined ? this.row.Number_of_Crew_Members__c : 0;
this.row.Labor_Total_Calculated__c = this.row.Days_Per_Crew__c * numberOfCrew;
this.handleChange();
}
handleNumberOfCrewMembersChange(event) {
this.row.Number_of_Crew_Members__c = event.detail.value;
let crewDays = this.row.Days_Per_Crew__c != undefined ? this.row.Days_Per_Crew__c : 0;
this.row.Labor_Total_Calculated__c = this.row.Number_of_Crew_Members__c * crewDays;
this.handleChange();
}