How to set editable as true only for certain users in Fullcalendar

1.7k views Asked by At

I am using Fullcalendar for my project and I was wondering how it is possible to set event editable only for selected users.

I have tried doing this but it didn't seem to work

editable: function (event) {   
    if (event.createdby == "Admin") {
        return true 
    }
    else {
        return false 
    }
},
1

There are 1 answers

1
Ataboy Josef On BEST ANSWER

The editable option determines if the events can be dragged and resized. Enables/disables both at the same time. I am not sure about the event.createdby call returns something like "Admin"(or any other user).

First you please check it by print it on console.log() or simply alert(event.createdby);. If this can show you Admin somehow, then it is all about the error in your code(like missing semicolon(;) after return true and return false in your code.

If you can take the name(or even id) of the 'selected user' to a variable like createdby, then it is just eazy as it is in the code below:

Change the code:

editable: function (event) {   
    if (event.createdby == "Admin") {
        return true 
    }
    else {
        return false 
    }
},

To this:

editable: (createdby == "Admin") ? true:false,

OR

editable: (createdid == 1) ? true:false,

Please note that createdby and createdid are javascript variables than contains selected user's name/id in your caledar.js file (as how you handle it in your project).

It is nothing about whether you use ASP, PHP, or MVC #... look how you can take uique users in the calendar.js file. There is a simple(best) way if you have the id in a hidden item in the content page.

That is by loading the value of the hidden field to the js variable like,

var createdid = $( "#idfield" ).val();

OR

var createdid = $( ".idfield" ).val();

Thank you.