pinned News

sayali deshpande asked on August 18, 2016 10:39

Hi,

I am working on Kentico 9. I want to restrict user to make 3 pinned news only. I have made Boolean field (checkbox)for pinning news.Now I am getting pinned news firstly appears and rest after that. Now I want to give limit to user that he can check only three news not more than that. And if he will trying to do check for pinning 4th news then it shows alert. Please suggest the solution on this. It will be really helpful. Thanks in advance.

Recent Answers


Dawid Jachnik answered on August 18, 2016 10:52

Hello, You can always display only 3 pinned news ordered by DocumentCreatedWhen or by your custom date field.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on August 18, 2016 10:56 (last edited on December 10, 2019 02:30)

You can add the validation for that field or completely hide the checkbox by following macro:

{%Documents.ClassNames("cms.news").WithAllData.Where("pinned=1").Count<3|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

sayali deshpande answered on August 18, 2016 12:32

hi Jan,

Macro is working for me but problem is If I want other important news is check and unchecked old one then I can't

0 votesVote for this answer Mark as a Correct answer

Richard Sustek answered on August 18, 2016 12:42

You need to use Order by condition so that the old news are not retrieved. If you are using Repeater to show the news then just type following in the order by property:

DocumentCreatedWhen desc

And thats it. You can also use other fields like NewsRelease column if you have one etc. The DocumentCreaetedWhen is a Kentico field that every page has.

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 18, 2016 16:49 (last edited on December 10, 2019 02:30)

Sayali,

You can modify Jan's code like this by adding an OR clause

{%Documents.ClassNames("cms.news").WithAllData.Where("pinned=1").Count<3 || CMSContext.Current.CurrentDocument.pinned ==1 |(identity)GlobalAdministrator%}

So this will check for whether no of documents < 3 or if document is already checked.

Try and let us know.

0 votesVote for this answer Mark as a Correct answer

sayali deshpande answered on August 22, 2016 06:52

Hi chetan, This code is also not working for me. After implementing this code it allows me to check all news item to pinned. Can you suggest me another way?

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 22, 2016 10:15

Okay sure, I am trying to replicate this locally. I will provide you some update shortly. What I would suggest you is to disable checkbox instead of showing alert. From a UX perspective.

0 votesVote for this answer Mark as a Correct answer

Nishant Khandelwal answered on March 29, 2017 21:10

Hi,

I am able to disable the checkbox once count is met its condition (which is 3 in above case) but after this I am unable to unchecked the check box.

Please assist.

0 votesVote for this answer Mark as a Correct answer

Nishant Khandelwal answered on March 29, 2017 21:28

Hi,

I resolved this issue by adding this below code

Documents.ClassNames("cms.news").WithAllData.Where("ForceToTop=1").Count<2 || EditedObject.GetValue("ForceToTop",1)

Thanks

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.