0

I have an iteration over the values of a picklist in a lightning component. It dynamically generates checkboxes for every value of this picklist.

I want to be able to use the value of this picklist to filter an array

When I apply this I get the error:

Action failed: c:checkboxFilter$controller$Techniek [opleidingen is not defined]

In this case Techniek is the fieldvalue on the object. How do I define a value of a field on an object

Here is my code Component

<aura:attribute name="opleidingen" type="Opleiding__c[]"/>  
<aura:attribute name="fieldName" Description="API Name of Picklist Value" type="String" />
<aura:attribute name="objectName" Description="API Name of the Object" type="Opleiding__c[]" />

<aura:attribute name="checkboxValue" type="Boolean" default="true" />

<aura:attribute name="records" type="object[]" description="" access="private" /> 
<div style="width:100%" class="slds-align_absolute-left">
    {!v.objectName}
    <aura:iteration items="{!v.records}" var="item" indexVar="indx"> 
        <ui:inputCheckbox aura:id="checkbox" 
                          value="{!item.checkboxValue}" 
                          text="{!item.fieldName}" 
                          name="{!indx}" 
                          label="{!item.fieldName}" 
                          change="{!c.Techniek}"/>&nbsp;{#item.val}     
    </aura:iteration> 

Javascript

 component.set("v.alleOpleidingen");
  var checkboxValue = event.getSource().get('v.value');// This is different in the documentation(Gianni).
  if(checkboxValue == true){
      console.log('Evaluates to true');

      var result = opleidingen.filter(function(opl)  {
                                      return typeof opl.Categorie__c === "{!v.label}";
                                      });
    component.set("v.Evaluates to true",result);  
     }    
  else{
  console.log('false');

I tried with JSON.stringify(opl.Categorie__c) but this give the same error

c:checkboxFilter$controller$Techniek [action is not defined]

3
  • Are you sure you posted the right code? Because you can't use the line: component.set("v.opleidingen"); You missed the second argument which should be the value you want to set to your variable. Also, the line: component.set("v.Evaluates to true",result); can't work. – Martin Lezer Jan 31 '18 at 8:16
  • @MartinLezer I did ran a debug with console.log('Evaluates to true'); which went well so I think so. My lightning component crashed this morning so I am waiting for salesforce to adress this I will check your remarks as soon as I can. – Thomas Jan 31 '18 at 10:52
  • @MartinLezer I updated the javascript part which is working at the moment and still have the mentioned error. – Thomas Feb 1 '18 at 9:07
1

The change attribute needs to reference a controller function (that you write) not a data field.

If Techniek is a custom field, you will need to include the __c too so Techniek__c.

Lightning Components support two way binding i.e. what is in the data model is presented on the screen and changes made on the screen are automatically pushed into the data model. So value="{!item.Techniek__c}" may be part of your solution.

I suggest you Google for examples that are close to what you are aiming to do and also go through some of the relevant Trailheads.

1
  • I think you misunderstood the code, Categorie__c in this case is the custom field. Techniek is the result of opl.Categorie__c which I compare with "{!v.label}". And to make things clearer c.Techniek is the function I call. The purpose of this is to make the c.Techniek function dynamic in the future based on value of opl.Categorie__c. – Thomas Feb 1 '18 at 9:14

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.