You need to sign in to do that
Don't have an account?
KARIM EL ALAOUI
Lithning component: bloc after if is not executed even the formula is true
Hello Everyone,
I don't know why the bloc after if is not executed even the formula is true
<aura:if isTrue="{!reclamation.Type__c == !v.category}">
when I do display the value of {!reclamation.Type__c} and {!v.category} the two values are similar
NB: the first value is coming from the object and the second value is coming from the picklist, and when I remplace the {!v.category} by a fixe value exemple 'Manque' the if condition works and the bloc after if is executed
*******
component:
<aura:component
implements="flexipage:availableForRecordHome,force:hasRecordId"
controller="ReclamationListController"
access="global"
>
<!-- Handler to call function when page is loaded initially -->
<aura:handler name="init" action="{!c.getReclamationsList}" value="{!this}" />
<!-- List of contacts stored in attribute -->
<aura:attribute name="reclamationList" type="List" />
<aura:attribute name="type" default="true" type="Boolean" />
<aura:attribute name="category" default="Excédent" type="String" />
<!-- Lightning card to show contacts -->
<lightning:card title="Reclamations">
<!-- **************************** -->
<lightning:select
aura:id="selectItem"
name="selectItem"
label="selectItem"
onchange="{! c.updateSelect }"
>
<option value="">choose one...</option>
<option value="Excédent">Excédent</option>
<option value="Retard">Retard</option>
<option value="Manque">Manque</option>
<option value="Autres">Autres</option>
</lightning:select>
<!-- **************************** -->
<!-- Body of lightning card starts here -->
<div class="slds-p-around_small">
<div class="slds-grid slds-wrap">
<aura:iteration items="{!v.reclamationList}" var="reclamation">
<aura:if isTrue="{!reclamation.Type__c == !v.category}">
<div
class="slds-col slds-size_1-of-3 slds-p-around_small slds-box slds-theme_shade slds-theme_alert-texture"
>
<a href="javascript:void(0);"> </a>
<lightning:card
title="{!reclamation.Name}"
footer="{!reclamation.Type__c}"
iconName="standard:contact"
>
<span class="slds-avatar">
<aura:if isTrue="{!reclamation.Type__c == 'Excédent'}">
<img
alt="Logo"
src="{!$Resource.Plus}"
title="User avatar"
/>
<aura:set attribute="else">
<img
alt="Logo"
src="{!$Resource.Minus}"
title="User avatar"
/>
</aura:set>
</aura:if>
</span>
<aura:set attribute="actions">
<lightning:button
name="{!reclamation.Id}"
label=" Details"
variant="Neutral"
onclick="{!c.doRedirect}"
/>
</aura:set>
<p class="slds-p-horizontal_small ? ' dix '">
{!reclamation.Description__c}
</p>
<tr
class="{!reclamation.Type__c == 'Excédent' ? ' exe ' :
reclamation.Type__c == 'Manque' ? ' mqe ' :
reclamation.Type__c == 'Retard' ? ' rtd ' :
reclamation.Type__c == 'Autres' ? ' oth ' : ''}"
>
<td data-label="Date:"> {!reclamation.Date__c} </td>
</tr>
</lightning:card>
</div>
</aura:if>
</aura:iteration>
</div>
</div>
<!-- Lightning card actions -->
<aura:set attribute="actions">
<!-- New button added -->
<lightning:button label="New" onclick="{!c.newReclamation}" />
</aura:set>
</lightning:card>
</aura:component>
*******************************
Controller:
({
// Function called on initial page loading to get contact list from server
getReclamationsList: function(component, event, helper) {
// Helper function - fetchRecalamations called for interaction with server
helper.fetchReclamations(component, event, helper);
},
updateSelect: function(component, event, helper) {
//return the selected value
var cat = component.find("selectItem").get("v.value");
alert(cat);
component.set("v.category", cat);
},
doRedirect: function(component, event, helper) {
var eventSource = event.getSource();
var id = eventSource.get("v.name");
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
recordId: id,
slideDevName: "detail"
});
navEvt.fire();
},
// Function used to create a new Reclamation
newReclamation: function(component, event, helper) {
// Global event force:createRecord is used
var createReclamation = $A.get("e.force:createRecord");
// Parameters like apiName and defaultValues are set
createReclamation.setParams({
entityApiName: "Reclamation__c",
defaultFieldValues: {
Contact__c: component.get("v.recordId")
}
});
// Event fired and new contact dialog open
createReclamation.fire();
}
});
thanks for your Help
I don't know why the bloc after if is not executed even the formula is true
<aura:if isTrue="{!reclamation.Type__c == !v.category}">
when I do display the value of {!reclamation.Type__c} and {!v.category} the two values are similar
NB: the first value is coming from the object and the second value is coming from the picklist, and when I remplace the {!v.category} by a fixe value exemple 'Manque' the if condition works and the bloc after if is executed
*******
component:
<aura:component
implements="flexipage:availableForRecordHome,force:hasRecordId"
controller="ReclamationListController"
access="global"
>
<!-- Handler to call function when page is loaded initially -->
<aura:handler name="init" action="{!c.getReclamationsList}" value="{!this}" />
<!-- List of contacts stored in attribute -->
<aura:attribute name="reclamationList" type="List" />
<aura:attribute name="type" default="true" type="Boolean" />
<aura:attribute name="category" default="Excédent" type="String" />
<!-- Lightning card to show contacts -->
<lightning:card title="Reclamations">
<!-- **************************** -->
<lightning:select
aura:id="selectItem"
name="selectItem"
label="selectItem"
onchange="{! c.updateSelect }"
>
<option value="">choose one...</option>
<option value="Excédent">Excédent</option>
<option value="Retard">Retard</option>
<option value="Manque">Manque</option>
<option value="Autres">Autres</option>
</lightning:select>
<!-- **************************** -->
<!-- Body of lightning card starts here -->
<div class="slds-p-around_small">
<div class="slds-grid slds-wrap">
<aura:iteration items="{!v.reclamationList}" var="reclamation">
<aura:if isTrue="{!reclamation.Type__c == !v.category}">
<div
class="slds-col slds-size_1-of-3 slds-p-around_small slds-box slds-theme_shade slds-theme_alert-texture"
>
<a href="javascript:void(0);"> </a>
<lightning:card
title="{!reclamation.Name}"
footer="{!reclamation.Type__c}"
iconName="standard:contact"
>
<span class="slds-avatar">
<aura:if isTrue="{!reclamation.Type__c == 'Excédent'}">
<img
alt="Logo"
src="{!$Resource.Plus}"
title="User avatar"
/>
<aura:set attribute="else">
<img
alt="Logo"
src="{!$Resource.Minus}"
title="User avatar"
/>
</aura:set>
</aura:if>
</span>
<aura:set attribute="actions">
<lightning:button
name="{!reclamation.Id}"
label=" Details"
variant="Neutral"
onclick="{!c.doRedirect}"
/>
</aura:set>
<p class="slds-p-horizontal_small ? ' dix '">
{!reclamation.Description__c}
</p>
<tr
class="{!reclamation.Type__c == 'Excédent' ? ' exe ' :
reclamation.Type__c == 'Manque' ? ' mqe ' :
reclamation.Type__c == 'Retard' ? ' rtd ' :
reclamation.Type__c == 'Autres' ? ' oth ' : ''}"
>
<td data-label="Date:"> {!reclamation.Date__c} </td>
</tr>
</lightning:card>
</div>
</aura:if>
</aura:iteration>
</div>
</div>
<!-- Lightning card actions -->
<aura:set attribute="actions">
<!-- New button added -->
<lightning:button label="New" onclick="{!c.newReclamation}" />
</aura:set>
</lightning:card>
</aura:component>
*******************************
Controller:
({
// Function called on initial page loading to get contact list from server
getReclamationsList: function(component, event, helper) {
// Helper function - fetchRecalamations called for interaction with server
helper.fetchReclamations(component, event, helper);
},
updateSelect: function(component, event, helper) {
//return the selected value
var cat = component.find("selectItem").get("v.value");
alert(cat);
component.set("v.category", cat);
},
doRedirect: function(component, event, helper) {
var eventSource = event.getSource();
var id = eventSource.get("v.name");
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
recordId: id,
slideDevName: "detail"
});
navEvt.fire();
},
// Function used to create a new Reclamation
newReclamation: function(component, event, helper) {
// Global event force:createRecord is used
var createReclamation = $A.get("e.force:createRecord");
// Parameters like apiName and defaultValues are set
createReclamation.setParams({
entityApiName: "Reclamation__c",
defaultFieldValues: {
Contact__c: component.get("v.recordId")
}
});
// Event fired and new contact dialog open
createReclamation.fire();
}
});
thanks for your Help
try this once
All Answers
try this once