Dynamic DataSource for Droplist in Content EditorRestrict Content Editor Language Dropdown OptionsHow do you...
What is Weapon Handling?
How can I become an invalid target for spells that target humanoids?
Fix Ethernet 10/100 PoE cable with 7 out of 8 wires alive
Garage door sticks on a bolt
How many stack cables would be needed if we want to stack two 3850 switches
Create the same subfolders in another folder
Knights and Knaves: What does C say?
Can I target any number of creatures, even if the ability would have no effect?
Does the app TikTok violate trademark?
what organs or modifications would be needed to have hairy fish?
What are examples of EU policies that are beneficial for one EU country, disadvantagious for another?
Why, even after his imprisonment, people keep calling Hannibal Lecter "Doctor"?
Do interval ratios take overtones into account or solely the fundamental frequency?
Selection Sort Algorithm (Python)
Codility's Permutation Check in C#
"until mine is on tight" is a idiom?
Dynamic DataSource for Droplist in Content Editor
I reverse the source code, you reverse the input!
Why Italian monolingual dictionaries usually take complex/archaic examples from books instead of creating simple examples?
How much horsepower to weight is required for a 1:1 thrust ratio
Which altitudes are safest for VFR?
Assembly of PCBs containing a mix of SMT and thru-hole parts?
How to stop the death waves in my city?
What would influence an alien race to map their planet in a way other than the traditional map of the Earth
Dynamic DataSource for Droplist in Content Editor
Restrict Content Editor Language Dropdown OptionsHow do you extend the item:new command without breaking a previous patch for it?Broken Links when using TokensMixed Content: The page at was loaded over HTTPS, but requested an insecure XMLHttpRequest endpointSitecore 9 - Authors accessing profile information for content itemsGetting a “Resource you are looking for has been removed” error in the datasource selection dialogPre-customize My Toolbar for users of a given role or domain?Different datasource for adding and changing rendering component contentContent and Experience Editor custom buttons - only show for certain roles
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have a Droplist for Approvers and the DataSource of Droplist to /SharedData/Approvers
.
I don't want the current user to have his own name in the list.
For example, DataSource List is having A, B and C
When A logs in, it should show B and C but not A. Or it should be validated when A selects himself as Approver.
Any idea?
sitecore-client content-editor validation
add a comment
|
I have a Droplist for Approvers and the DataSource of Droplist to /SharedData/Approvers
.
I don't want the current user to have his own name in the list.
For example, DataSource List is having A, B and C
When A logs in, it should show B and C but not A. Or it should be validated when A selects himself as Approver.
Any idea?
sitecore-client content-editor validation
add a comment
|
I have a Droplist for Approvers and the DataSource of Droplist to /SharedData/Approvers
.
I don't want the current user to have his own name in the list.
For example, DataSource List is having A, B and C
When A logs in, it should show B and C but not A. Or it should be validated when A selects himself as Approver.
Any idea?
sitecore-client content-editor validation
I have a Droplist for Approvers and the DataSource of Droplist to /SharedData/Approvers
.
I don't want the current user to have his own name in the list.
For example, DataSource List is having A, B and C
When A logs in, it should show B and C but not A. Or it should be validated when A selects himself as Approver.
Any idea?
sitecore-client content-editor validation
sitecore-client content-editor validation
edited 7 hours ago
Hishaam Namooya
7,0671 gold badge8 silver badges28 bronze badges
7,0671 gold badge8 silver badges28 bronze badges
asked 9 hours ago
user3621user3621
1096 bronze badges
1096 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
It is possible via both a custom field implementation or field validation. Below is the code for both ways.
Solution 1 - A Custom Validation
You should implement a class which will extend the StandardValidator
. The code snippet is provided below to create a custom validation for the droplist.
[Serializable]
public class UserValidation : StandardValidator
{
protected override ValidatorResult Evaluate()
{
var selectedValue = ControlValidationValue;
var username = Context.User.LocalName;
if (!selectedValue.IsNullOrEmpty() && selectedValue.Equals(username))
{
Text = GetText($"Field {GetFieldDisplayName()} cannot select your own name");
return ValidatorResult.FatalError;
}
return ValidatorResult.Valid;
}
protected override ValidatorResult GetMaxValidatorResult()
{
return GetFailedResult(ValidatorResult.Error);
}
public override string Name => "User Validator";
}
In the code above, I have use the LocalName
property. This property will return me only the name. Example, Admin.
Note that this piece of code will validate the username against the item name. It is feasible check the username against a field on the items from the list but it will require additional code to retrieve the selected item then read the field.
Once you have deployed the above code, you will need to create a new validation item under the path /sitecore/system/Settings/Validation Rules/Field Rules
.
Change the Type
to match your namespace. Also, you need to assign the newly created validation rule to the field.
Solution 2 - A Custom Field
You can implement a custom droplist which extend the ValueLookupEx
from the namespace Sitecore.Shell.Applications.ContentEditor
in the Sitecore.Kernel.dll
. The purpose will be to remove the current user from the list of items if it matches.
public class CustomDroplist : ValueLookupEx
{
protected override Item[] GetItems(Item current)
{
var items = base.GetItems(current);
var username = Sitecore.Context.User.LocalName;
var resultItems = items.Where(w => !w.Name.Equals(username)).ToArray();
return resultItems;
}
}
Once implemented, deploy the code and load the content editor. Then, switch the database to core
and navigate to the path /sitecore/system/Field types/List Types
and create a new field using the template Template field type
.
Update the assembly and class with yours.
Outcome
add a comment
|
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "664"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f22221%2fdynamic-datasource-for-droplist-in-content-editor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It is possible via both a custom field implementation or field validation. Below is the code for both ways.
Solution 1 - A Custom Validation
You should implement a class which will extend the StandardValidator
. The code snippet is provided below to create a custom validation for the droplist.
[Serializable]
public class UserValidation : StandardValidator
{
protected override ValidatorResult Evaluate()
{
var selectedValue = ControlValidationValue;
var username = Context.User.LocalName;
if (!selectedValue.IsNullOrEmpty() && selectedValue.Equals(username))
{
Text = GetText($"Field {GetFieldDisplayName()} cannot select your own name");
return ValidatorResult.FatalError;
}
return ValidatorResult.Valid;
}
protected override ValidatorResult GetMaxValidatorResult()
{
return GetFailedResult(ValidatorResult.Error);
}
public override string Name => "User Validator";
}
In the code above, I have use the LocalName
property. This property will return me only the name. Example, Admin.
Note that this piece of code will validate the username against the item name. It is feasible check the username against a field on the items from the list but it will require additional code to retrieve the selected item then read the field.
Once you have deployed the above code, you will need to create a new validation item under the path /sitecore/system/Settings/Validation Rules/Field Rules
.
Change the Type
to match your namespace. Also, you need to assign the newly created validation rule to the field.
Solution 2 - A Custom Field
You can implement a custom droplist which extend the ValueLookupEx
from the namespace Sitecore.Shell.Applications.ContentEditor
in the Sitecore.Kernel.dll
. The purpose will be to remove the current user from the list of items if it matches.
public class CustomDroplist : ValueLookupEx
{
protected override Item[] GetItems(Item current)
{
var items = base.GetItems(current);
var username = Sitecore.Context.User.LocalName;
var resultItems = items.Where(w => !w.Name.Equals(username)).ToArray();
return resultItems;
}
}
Once implemented, deploy the code and load the content editor. Then, switch the database to core
and navigate to the path /sitecore/system/Field types/List Types
and create a new field using the template Template field type
.
Update the assembly and class with yours.
Outcome
add a comment
|
It is possible via both a custom field implementation or field validation. Below is the code for both ways.
Solution 1 - A Custom Validation
You should implement a class which will extend the StandardValidator
. The code snippet is provided below to create a custom validation for the droplist.
[Serializable]
public class UserValidation : StandardValidator
{
protected override ValidatorResult Evaluate()
{
var selectedValue = ControlValidationValue;
var username = Context.User.LocalName;
if (!selectedValue.IsNullOrEmpty() && selectedValue.Equals(username))
{
Text = GetText($"Field {GetFieldDisplayName()} cannot select your own name");
return ValidatorResult.FatalError;
}
return ValidatorResult.Valid;
}
protected override ValidatorResult GetMaxValidatorResult()
{
return GetFailedResult(ValidatorResult.Error);
}
public override string Name => "User Validator";
}
In the code above, I have use the LocalName
property. This property will return me only the name. Example, Admin.
Note that this piece of code will validate the username against the item name. It is feasible check the username against a field on the items from the list but it will require additional code to retrieve the selected item then read the field.
Once you have deployed the above code, you will need to create a new validation item under the path /sitecore/system/Settings/Validation Rules/Field Rules
.
Change the Type
to match your namespace. Also, you need to assign the newly created validation rule to the field.
Solution 2 - A Custom Field
You can implement a custom droplist which extend the ValueLookupEx
from the namespace Sitecore.Shell.Applications.ContentEditor
in the Sitecore.Kernel.dll
. The purpose will be to remove the current user from the list of items if it matches.
public class CustomDroplist : ValueLookupEx
{
protected override Item[] GetItems(Item current)
{
var items = base.GetItems(current);
var username = Sitecore.Context.User.LocalName;
var resultItems = items.Where(w => !w.Name.Equals(username)).ToArray();
return resultItems;
}
}
Once implemented, deploy the code and load the content editor. Then, switch the database to core
and navigate to the path /sitecore/system/Field types/List Types
and create a new field using the template Template field type
.
Update the assembly and class with yours.
Outcome
add a comment
|
It is possible via both a custom field implementation or field validation. Below is the code for both ways.
Solution 1 - A Custom Validation
You should implement a class which will extend the StandardValidator
. The code snippet is provided below to create a custom validation for the droplist.
[Serializable]
public class UserValidation : StandardValidator
{
protected override ValidatorResult Evaluate()
{
var selectedValue = ControlValidationValue;
var username = Context.User.LocalName;
if (!selectedValue.IsNullOrEmpty() && selectedValue.Equals(username))
{
Text = GetText($"Field {GetFieldDisplayName()} cannot select your own name");
return ValidatorResult.FatalError;
}
return ValidatorResult.Valid;
}
protected override ValidatorResult GetMaxValidatorResult()
{
return GetFailedResult(ValidatorResult.Error);
}
public override string Name => "User Validator";
}
In the code above, I have use the LocalName
property. This property will return me only the name. Example, Admin.
Note that this piece of code will validate the username against the item name. It is feasible check the username against a field on the items from the list but it will require additional code to retrieve the selected item then read the field.
Once you have deployed the above code, you will need to create a new validation item under the path /sitecore/system/Settings/Validation Rules/Field Rules
.
Change the Type
to match your namespace. Also, you need to assign the newly created validation rule to the field.
Solution 2 - A Custom Field
You can implement a custom droplist which extend the ValueLookupEx
from the namespace Sitecore.Shell.Applications.ContentEditor
in the Sitecore.Kernel.dll
. The purpose will be to remove the current user from the list of items if it matches.
public class CustomDroplist : ValueLookupEx
{
protected override Item[] GetItems(Item current)
{
var items = base.GetItems(current);
var username = Sitecore.Context.User.LocalName;
var resultItems = items.Where(w => !w.Name.Equals(username)).ToArray();
return resultItems;
}
}
Once implemented, deploy the code and load the content editor. Then, switch the database to core
and navigate to the path /sitecore/system/Field types/List Types
and create a new field using the template Template field type
.
Update the assembly and class with yours.
Outcome
It is possible via both a custom field implementation or field validation. Below is the code for both ways.
Solution 1 - A Custom Validation
You should implement a class which will extend the StandardValidator
. The code snippet is provided below to create a custom validation for the droplist.
[Serializable]
public class UserValidation : StandardValidator
{
protected override ValidatorResult Evaluate()
{
var selectedValue = ControlValidationValue;
var username = Context.User.LocalName;
if (!selectedValue.IsNullOrEmpty() && selectedValue.Equals(username))
{
Text = GetText($"Field {GetFieldDisplayName()} cannot select your own name");
return ValidatorResult.FatalError;
}
return ValidatorResult.Valid;
}
protected override ValidatorResult GetMaxValidatorResult()
{
return GetFailedResult(ValidatorResult.Error);
}
public override string Name => "User Validator";
}
In the code above, I have use the LocalName
property. This property will return me only the name. Example, Admin.
Note that this piece of code will validate the username against the item name. It is feasible check the username against a field on the items from the list but it will require additional code to retrieve the selected item then read the field.
Once you have deployed the above code, you will need to create a new validation item under the path /sitecore/system/Settings/Validation Rules/Field Rules
.
Change the Type
to match your namespace. Also, you need to assign the newly created validation rule to the field.
Solution 2 - A Custom Field
You can implement a custom droplist which extend the ValueLookupEx
from the namespace Sitecore.Shell.Applications.ContentEditor
in the Sitecore.Kernel.dll
. The purpose will be to remove the current user from the list of items if it matches.
public class CustomDroplist : ValueLookupEx
{
protected override Item[] GetItems(Item current)
{
var items = base.GetItems(current);
var username = Sitecore.Context.User.LocalName;
var resultItems = items.Where(w => !w.Name.Equals(username)).ToArray();
return resultItems;
}
}
Once implemented, deploy the code and load the content editor. Then, switch the database to core
and navigate to the path /sitecore/system/Field types/List Types
and create a new field using the template Template field type
.
Update the assembly and class with yours.
Outcome
answered 7 hours ago
Hishaam NamooyaHishaam Namooya
7,0671 gold badge8 silver badges28 bronze badges
7,0671 gold badge8 silver badges28 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Sitecore Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f22221%2fdynamic-datasource-for-droplist-in-content-editor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown