0

Please refer to below markup.

<lightning-record-edit-form key={field.key} object-api-name="Callback__c" layout-type="Full" >
   <div class="slds-grid slds-wrap">
       <template for:each={field.lstFields} for:item="fieldList" >
           <lightning-input-field if:true={isField} key={fieldList.key} field-name={fieldList.fieldName} class="slds-col slds-size_1-of-2"> 
           </lightning-input-field>
        </template>
    </div>
</lightning-record-edit-form>

Is it possible to fetch a value of {fieldList.fieldName} in javascript function isField() of lightning web component?

I want to check if fieldname='x' in lightning-input-field tage.

  • 2
    What exactly is the requirement? – salesforce-sas Sep 18 '19 at 2:50
0

If you need to set something specific to each loop (iteration), you need to set the condition on loop variable (in each object).

HTML:

    <lightning-button label="Toggle Type" onclick={toggleType}></lightning-button>
    <lightning-record-edit-form object-api-name="Account">
        <template for:each={fields} for:item="fld">
            <lightning-input-field key={fld.name}
                                   field-name={fld.name}
                                   if:true={fld.render}>
            </lightning-input-field>
        </template>
    </lightning-record-edit-form>

JS:

@track fields = [
    { name: 'Name', render: true },
    { name: 'Type', render: false },
    { name: 'Rating', render: true }
];

toggleType() {
    this.fields.find(fld => fld.name === 'Type').render = !this.fields.find(fld => fld.name === 'Type').render;
}

On click of Toggle Type, it will show or hide the field Type.

  • Thanks @salesforce-sas for your answer. But I was looking for if condition with arithmetic operators like if:true="{isField=='xyz'}. though later on I got to know that in lightning web component you can't use arithmetic operators in if condition. You have to do that in javascript. – Juhi Sep 19 '19 at 3:22

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.