0

I make use of a checkbox in my component which fires a function on my controller.

The condition does not work I cant figure out why, there is no error in my log, here is my code:

Component

<lightning:input type="checkbox" label="Afgelopen 30 dagen" 
    onchange="{!c.Afgelopen30dagen}"/><br/>

Controller

Afgelopen30dagen: function(component, event) {
    var itemList = component.get("v.opleidingen");
    var newList = [];
    var today = new Date();
    for (var item of itemList){
         if(item.Startdatum__c > today-30){
            newList.push(item);
        }
        component.set('v.opleidingen',newList);    
    }
}

1 Answer 1

1

I figured out that the javascript date needed to be formatted. What I ended up with working is:

Afgelopen30dagen: function(component, event) {
var itemList = component.get("v.opleidingen");
var newList = [];
var today = new Date();        
var dd = today.getDate()-30;
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();    
// if date is less then 10, then append 0 before date   
    if(dd < 10){
        dd = '0' + dd;
    } 
// if month is less then 10, then append 0 before date    
    if(mm < 10){
        mm = '0' + mm;
    }    
var todayFormattedDate = yyyy+'-'+mm+'-'+dd;   
for (var item of itemList){
if(item.Startdatum__c > todayFormattedDate){
newList.push(item);
}
component.set('v.opleidingen',newList);    
}} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .