Make one of two sitecore content fields required?
I've been trying to find a way to make one of two fields valid and haven't come up with much. Is there a way to do this with custom field validators or is that just relevant to individual fields? The requirement is that one of two fields must be filled in, probably only one, but even if that's not possible, just having at least one filled in (and then there being a default in terms of which is used) would be acceptable, I suppose.
content-editor validation
add a comment |
I've been trying to find a way to make one of two fields valid and haven't come up with much. Is there a way to do this with custom field validators or is that just relevant to individual fields? The requirement is that one of two fields must be filled in, probably only one, but even if that's not possible, just having at least one filled in (and then there being a default in terms of which is used) would be acceptable, I suppose.
content-editor validation
Nothing OOTB, but there may be a way to achieve what you are looking for via breaking up your content appropriately into different templates. For example, if you have two datasource templates, you could have different rules for validation. The author picks which template they want to use by selecting compatible renderings. It may help to know more about your specific authoring scenario to help guide you.
– Jason St-Cyr
Jan 7 at 15:23
add a comment |
I've been trying to find a way to make one of two fields valid and haven't come up with much. Is there a way to do this with custom field validators or is that just relevant to individual fields? The requirement is that one of two fields must be filled in, probably only one, but even if that's not possible, just having at least one filled in (and then there being a default in terms of which is used) would be acceptable, I suppose.
content-editor validation
I've been trying to find a way to make one of two fields valid and haven't come up with much. Is there a way to do this with custom field validators or is that just relevant to individual fields? The requirement is that one of two fields must be filled in, probably only one, but even if that's not possible, just having at least one filled in (and then there being a default in terms of which is used) would be acceptable, I suppose.
content-editor validation
content-editor validation
asked Jan 7 at 14:55
Levi WallachLevi Wallach
1666
1666
Nothing OOTB, but there may be a way to achieve what you are looking for via breaking up your content appropriately into different templates. For example, if you have two datasource templates, you could have different rules for validation. The author picks which template they want to use by selecting compatible renderings. It may help to know more about your specific authoring scenario to help guide you.
– Jason St-Cyr
Jan 7 at 15:23
add a comment |
Nothing OOTB, but there may be a way to achieve what you are looking for via breaking up your content appropriately into different templates. For example, if you have two datasource templates, you could have different rules for validation. The author picks which template they want to use by selecting compatible renderings. It may help to know more about your specific authoring scenario to help guide you.
– Jason St-Cyr
Jan 7 at 15:23
Nothing OOTB, but there may be a way to achieve what you are looking for via breaking up your content appropriately into different templates. For example, if you have two datasource templates, you could have different rules for validation. The author picks which template they want to use by selecting compatible renderings. It may help to know more about your specific authoring scenario to help guide you.
– Jason St-Cyr
Jan 7 at 15:23
Nothing OOTB, but there may be a way to achieve what you are looking for via breaking up your content appropriately into different templates. For example, if you have two datasource templates, you could have different rules for validation. The author picks which template they want to use by selecting compatible renderings. It may help to know more about your specific authoring scenario to help guide you.
– Jason St-Cyr
Jan 7 at 15:23
add a comment |
2 Answers
2
active
oldest
votes
There is nothing out of the box that will do this for you as far as I am aware and although you think it might be possible custom validation I don't think it is as the a validator works on only one field at a time so updates to the item would only have the updated data for that single field and not the other field. Therefore I think your only option here might be to use the item:saving
event to validate the data there as mentioned by Richard Seal below:
Item validator access already stored data instead of newly inputed data
You need to be careful with this though to make sure it doesn't fire all of the time. Maybe you could check the template before running this validation or something.
Another related thread on SSE is here:
Apply field validations across fields
Yeah, talking to another developer we already it seems have a custom validator that's doing something via the item:saving event, so I should be able to just tack this additional validation on to it. Thanks for helping me pinpoint the issue and solution.
– Levi Wallach
Jan 7 at 15:27
No worries. I come across these kind of scenarios now and again and sometimes you can just handle the display logic in the controller before rendering and through Content Editor education. It would be useful if we could do this more easily with Custom Validators though.
– Adam Seabridge
Jan 7 at 15:37
add a comment |
I would recommend implementing a custom Item validation rule.
Note: This is different from a field validation, in that it validates the entire item instead of a single field.
1. Create custom validator
Create a new class that implements the Sitecore.Data.Validators.StandardValidator
base class. In the Evaluate()
method, get both fields and check to see if either of them has a value:
public class AtLeastOneFieldPopulatedValidator : StandardValidator
{
public override string Name => "At Least One Field Populated";
public AtLeastOneFieldPopulatedValidator() {}
public UrlCharacterValidator(SerializationInfo info, StreamingContext context) : base(info, context) {}
protected override ValidatorResult Evaluate()
{
Item item = base.GetItem();
if (item == null)
{
return ValidatorResult.Valid;
}
if (!string.IsNullOrEmpty(item["Field 1"]) || !string.IsNullOrEmpty(item["Field 2"]))
{
return ValidatorResult.Valid;
}
return base.GetFailedResult(ValidatorResult.CriticalError);
}
protected override ValidatorResult GetMaxValidatorResult()
{
return base.GetFailedResult(ValidatorResult.Error);
}
}
2. Create Validation Rule
item
First, create a new Validation Rule
(template /sitecore/templates/System/Validation/Validation Rule
) item somewhere below this node:
/sitecore/system/Settings/Validation Rules/Item Rules
Important: Make sure you populate the
Type
field with your fully-qualified name of your custom validator's class (e.g.Custom.Services.AtLeastOneFieldPopulatedValidator, Custom.Services
).
3. Associate your Validation Rule
to your items
On the __Standard values
of your item's template, show Standard Fields (View ribbon tab -> Standard fields) and add your Validation Rule
to the appropriate validation fields. I recommend including it in all four.
(Optional) Extra credit: Add parameters
I've not tested this, but I'm sure there's a way to pass parameters using the Parameters
field on the Validation Rule
item. In these parameters, you could pass a list of the fields to check so your validator can be reused by creating multiple Validation Rule
items in Sitecore.
did you test this code? It would be great if it works but my understanding is that item["Field 2"] would not have a value at the point the validation for item["Field 1"] fires. This is mentioned in the SSE posts I've referenced in my answer.
– Adam Seabridge
Jan 7 at 18:19
I believe this will be different, however, because this is an Item validator (not a field validator). I believe it still runs after every field is updated (I haven't dug through the CE JS to verify that), but it validates the entire item instead of just a single field.
– Dan Sinclair
Jan 7 at 18:23
It also appears this is the same solution they used in the second SSE post you linked: "We additionally put an item validator on the component itself to prevent it from going through workflow."
– Dan Sinclair
Jan 7 at 18:25
Ahr right, sorry yes it's not a field validator so the values should both be set. No worries then.
– Adam Seabridge
Jan 7 at 18:30
@AdamSeabridge you point out a valid concern, though, that it was not clear. I've edited the answer to attempt to call that out more clearly.
– Dan Sinclair
Jan 7 at 18:34
|
show 6 more comments
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/3.0/"u003ecc by-sa 3.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%2f15890%2fmake-one-of-two-sitecore-content-fields-required%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There is nothing out of the box that will do this for you as far as I am aware and although you think it might be possible custom validation I don't think it is as the a validator works on only one field at a time so updates to the item would only have the updated data for that single field and not the other field. Therefore I think your only option here might be to use the item:saving
event to validate the data there as mentioned by Richard Seal below:
Item validator access already stored data instead of newly inputed data
You need to be careful with this though to make sure it doesn't fire all of the time. Maybe you could check the template before running this validation or something.
Another related thread on SSE is here:
Apply field validations across fields
Yeah, talking to another developer we already it seems have a custom validator that's doing something via the item:saving event, so I should be able to just tack this additional validation on to it. Thanks for helping me pinpoint the issue and solution.
– Levi Wallach
Jan 7 at 15:27
No worries. I come across these kind of scenarios now and again and sometimes you can just handle the display logic in the controller before rendering and through Content Editor education. It would be useful if we could do this more easily with Custom Validators though.
– Adam Seabridge
Jan 7 at 15:37
add a comment |
There is nothing out of the box that will do this for you as far as I am aware and although you think it might be possible custom validation I don't think it is as the a validator works on only one field at a time so updates to the item would only have the updated data for that single field and not the other field. Therefore I think your only option here might be to use the item:saving
event to validate the data there as mentioned by Richard Seal below:
Item validator access already stored data instead of newly inputed data
You need to be careful with this though to make sure it doesn't fire all of the time. Maybe you could check the template before running this validation or something.
Another related thread on SSE is here:
Apply field validations across fields
Yeah, talking to another developer we already it seems have a custom validator that's doing something via the item:saving event, so I should be able to just tack this additional validation on to it. Thanks for helping me pinpoint the issue and solution.
– Levi Wallach
Jan 7 at 15:27
No worries. I come across these kind of scenarios now and again and sometimes you can just handle the display logic in the controller before rendering and through Content Editor education. It would be useful if we could do this more easily with Custom Validators though.
– Adam Seabridge
Jan 7 at 15:37
add a comment |
There is nothing out of the box that will do this for you as far as I am aware and although you think it might be possible custom validation I don't think it is as the a validator works on only one field at a time so updates to the item would only have the updated data for that single field and not the other field. Therefore I think your only option here might be to use the item:saving
event to validate the data there as mentioned by Richard Seal below:
Item validator access already stored data instead of newly inputed data
You need to be careful with this though to make sure it doesn't fire all of the time. Maybe you could check the template before running this validation or something.
Another related thread on SSE is here:
Apply field validations across fields
There is nothing out of the box that will do this for you as far as I am aware and although you think it might be possible custom validation I don't think it is as the a validator works on only one field at a time so updates to the item would only have the updated data for that single field and not the other field. Therefore I think your only option here might be to use the item:saving
event to validate the data there as mentioned by Richard Seal below:
Item validator access already stored data instead of newly inputed data
You need to be careful with this though to make sure it doesn't fire all of the time. Maybe you could check the template before running this validation or something.
Another related thread on SSE is here:
Apply field validations across fields
answered Jan 7 at 15:08
Adam SeabridgeAdam Seabridge
6,2301349
6,2301349
Yeah, talking to another developer we already it seems have a custom validator that's doing something via the item:saving event, so I should be able to just tack this additional validation on to it. Thanks for helping me pinpoint the issue and solution.
– Levi Wallach
Jan 7 at 15:27
No worries. I come across these kind of scenarios now and again and sometimes you can just handle the display logic in the controller before rendering and through Content Editor education. It would be useful if we could do this more easily with Custom Validators though.
– Adam Seabridge
Jan 7 at 15:37
add a comment |
Yeah, talking to another developer we already it seems have a custom validator that's doing something via the item:saving event, so I should be able to just tack this additional validation on to it. Thanks for helping me pinpoint the issue and solution.
– Levi Wallach
Jan 7 at 15:27
No worries. I come across these kind of scenarios now and again and sometimes you can just handle the display logic in the controller before rendering and through Content Editor education. It would be useful if we could do this more easily with Custom Validators though.
– Adam Seabridge
Jan 7 at 15:37
Yeah, talking to another developer we already it seems have a custom validator that's doing something via the item:saving event, so I should be able to just tack this additional validation on to it. Thanks for helping me pinpoint the issue and solution.
– Levi Wallach
Jan 7 at 15:27
Yeah, talking to another developer we already it seems have a custom validator that's doing something via the item:saving event, so I should be able to just tack this additional validation on to it. Thanks for helping me pinpoint the issue and solution.
– Levi Wallach
Jan 7 at 15:27
No worries. I come across these kind of scenarios now and again and sometimes you can just handle the display logic in the controller before rendering and through Content Editor education. It would be useful if we could do this more easily with Custom Validators though.
– Adam Seabridge
Jan 7 at 15:37
No worries. I come across these kind of scenarios now and again and sometimes you can just handle the display logic in the controller before rendering and through Content Editor education. It would be useful if we could do this more easily with Custom Validators though.
– Adam Seabridge
Jan 7 at 15:37
add a comment |
I would recommend implementing a custom Item validation rule.
Note: This is different from a field validation, in that it validates the entire item instead of a single field.
1. Create custom validator
Create a new class that implements the Sitecore.Data.Validators.StandardValidator
base class. In the Evaluate()
method, get both fields and check to see if either of them has a value:
public class AtLeastOneFieldPopulatedValidator : StandardValidator
{
public override string Name => "At Least One Field Populated";
public AtLeastOneFieldPopulatedValidator() {}
public UrlCharacterValidator(SerializationInfo info, StreamingContext context) : base(info, context) {}
protected override ValidatorResult Evaluate()
{
Item item = base.GetItem();
if (item == null)
{
return ValidatorResult.Valid;
}
if (!string.IsNullOrEmpty(item["Field 1"]) || !string.IsNullOrEmpty(item["Field 2"]))
{
return ValidatorResult.Valid;
}
return base.GetFailedResult(ValidatorResult.CriticalError);
}
protected override ValidatorResult GetMaxValidatorResult()
{
return base.GetFailedResult(ValidatorResult.Error);
}
}
2. Create Validation Rule
item
First, create a new Validation Rule
(template /sitecore/templates/System/Validation/Validation Rule
) item somewhere below this node:
/sitecore/system/Settings/Validation Rules/Item Rules
Important: Make sure you populate the
Type
field with your fully-qualified name of your custom validator's class (e.g.Custom.Services.AtLeastOneFieldPopulatedValidator, Custom.Services
).
3. Associate your Validation Rule
to your items
On the __Standard values
of your item's template, show Standard Fields (View ribbon tab -> Standard fields) and add your Validation Rule
to the appropriate validation fields. I recommend including it in all four.
(Optional) Extra credit: Add parameters
I've not tested this, but I'm sure there's a way to pass parameters using the Parameters
field on the Validation Rule
item. In these parameters, you could pass a list of the fields to check so your validator can be reused by creating multiple Validation Rule
items in Sitecore.
did you test this code? It would be great if it works but my understanding is that item["Field 2"] would not have a value at the point the validation for item["Field 1"] fires. This is mentioned in the SSE posts I've referenced in my answer.
– Adam Seabridge
Jan 7 at 18:19
I believe this will be different, however, because this is an Item validator (not a field validator). I believe it still runs after every field is updated (I haven't dug through the CE JS to verify that), but it validates the entire item instead of just a single field.
– Dan Sinclair
Jan 7 at 18:23
It also appears this is the same solution they used in the second SSE post you linked: "We additionally put an item validator on the component itself to prevent it from going through workflow."
– Dan Sinclair
Jan 7 at 18:25
Ahr right, sorry yes it's not a field validator so the values should both be set. No worries then.
– Adam Seabridge
Jan 7 at 18:30
@AdamSeabridge you point out a valid concern, though, that it was not clear. I've edited the answer to attempt to call that out more clearly.
– Dan Sinclair
Jan 7 at 18:34
|
show 6 more comments
I would recommend implementing a custom Item validation rule.
Note: This is different from a field validation, in that it validates the entire item instead of a single field.
1. Create custom validator
Create a new class that implements the Sitecore.Data.Validators.StandardValidator
base class. In the Evaluate()
method, get both fields and check to see if either of them has a value:
public class AtLeastOneFieldPopulatedValidator : StandardValidator
{
public override string Name => "At Least One Field Populated";
public AtLeastOneFieldPopulatedValidator() {}
public UrlCharacterValidator(SerializationInfo info, StreamingContext context) : base(info, context) {}
protected override ValidatorResult Evaluate()
{
Item item = base.GetItem();
if (item == null)
{
return ValidatorResult.Valid;
}
if (!string.IsNullOrEmpty(item["Field 1"]) || !string.IsNullOrEmpty(item["Field 2"]))
{
return ValidatorResult.Valid;
}
return base.GetFailedResult(ValidatorResult.CriticalError);
}
protected override ValidatorResult GetMaxValidatorResult()
{
return base.GetFailedResult(ValidatorResult.Error);
}
}
2. Create Validation Rule
item
First, create a new Validation Rule
(template /sitecore/templates/System/Validation/Validation Rule
) item somewhere below this node:
/sitecore/system/Settings/Validation Rules/Item Rules
Important: Make sure you populate the
Type
field with your fully-qualified name of your custom validator's class (e.g.Custom.Services.AtLeastOneFieldPopulatedValidator, Custom.Services
).
3. Associate your Validation Rule
to your items
On the __Standard values
of your item's template, show Standard Fields (View ribbon tab -> Standard fields) and add your Validation Rule
to the appropriate validation fields. I recommend including it in all four.
(Optional) Extra credit: Add parameters
I've not tested this, but I'm sure there's a way to pass parameters using the Parameters
field on the Validation Rule
item. In these parameters, you could pass a list of the fields to check so your validator can be reused by creating multiple Validation Rule
items in Sitecore.
did you test this code? It would be great if it works but my understanding is that item["Field 2"] would not have a value at the point the validation for item["Field 1"] fires. This is mentioned in the SSE posts I've referenced in my answer.
– Adam Seabridge
Jan 7 at 18:19
I believe this will be different, however, because this is an Item validator (not a field validator). I believe it still runs after every field is updated (I haven't dug through the CE JS to verify that), but it validates the entire item instead of just a single field.
– Dan Sinclair
Jan 7 at 18:23
It also appears this is the same solution they used in the second SSE post you linked: "We additionally put an item validator on the component itself to prevent it from going through workflow."
– Dan Sinclair
Jan 7 at 18:25
Ahr right, sorry yes it's not a field validator so the values should both be set. No worries then.
– Adam Seabridge
Jan 7 at 18:30
@AdamSeabridge you point out a valid concern, though, that it was not clear. I've edited the answer to attempt to call that out more clearly.
– Dan Sinclair
Jan 7 at 18:34
|
show 6 more comments
I would recommend implementing a custom Item validation rule.
Note: This is different from a field validation, in that it validates the entire item instead of a single field.
1. Create custom validator
Create a new class that implements the Sitecore.Data.Validators.StandardValidator
base class. In the Evaluate()
method, get both fields and check to see if either of them has a value:
public class AtLeastOneFieldPopulatedValidator : StandardValidator
{
public override string Name => "At Least One Field Populated";
public AtLeastOneFieldPopulatedValidator() {}
public UrlCharacterValidator(SerializationInfo info, StreamingContext context) : base(info, context) {}
protected override ValidatorResult Evaluate()
{
Item item = base.GetItem();
if (item == null)
{
return ValidatorResult.Valid;
}
if (!string.IsNullOrEmpty(item["Field 1"]) || !string.IsNullOrEmpty(item["Field 2"]))
{
return ValidatorResult.Valid;
}
return base.GetFailedResult(ValidatorResult.CriticalError);
}
protected override ValidatorResult GetMaxValidatorResult()
{
return base.GetFailedResult(ValidatorResult.Error);
}
}
2. Create Validation Rule
item
First, create a new Validation Rule
(template /sitecore/templates/System/Validation/Validation Rule
) item somewhere below this node:
/sitecore/system/Settings/Validation Rules/Item Rules
Important: Make sure you populate the
Type
field with your fully-qualified name of your custom validator's class (e.g.Custom.Services.AtLeastOneFieldPopulatedValidator, Custom.Services
).
3. Associate your Validation Rule
to your items
On the __Standard values
of your item's template, show Standard Fields (View ribbon tab -> Standard fields) and add your Validation Rule
to the appropriate validation fields. I recommend including it in all four.
(Optional) Extra credit: Add parameters
I've not tested this, but I'm sure there's a way to pass parameters using the Parameters
field on the Validation Rule
item. In these parameters, you could pass a list of the fields to check so your validator can be reused by creating multiple Validation Rule
items in Sitecore.
I would recommend implementing a custom Item validation rule.
Note: This is different from a field validation, in that it validates the entire item instead of a single field.
1. Create custom validator
Create a new class that implements the Sitecore.Data.Validators.StandardValidator
base class. In the Evaluate()
method, get both fields and check to see if either of them has a value:
public class AtLeastOneFieldPopulatedValidator : StandardValidator
{
public override string Name => "At Least One Field Populated";
public AtLeastOneFieldPopulatedValidator() {}
public UrlCharacterValidator(SerializationInfo info, StreamingContext context) : base(info, context) {}
protected override ValidatorResult Evaluate()
{
Item item = base.GetItem();
if (item == null)
{
return ValidatorResult.Valid;
}
if (!string.IsNullOrEmpty(item["Field 1"]) || !string.IsNullOrEmpty(item["Field 2"]))
{
return ValidatorResult.Valid;
}
return base.GetFailedResult(ValidatorResult.CriticalError);
}
protected override ValidatorResult GetMaxValidatorResult()
{
return base.GetFailedResult(ValidatorResult.Error);
}
}
2. Create Validation Rule
item
First, create a new Validation Rule
(template /sitecore/templates/System/Validation/Validation Rule
) item somewhere below this node:
/sitecore/system/Settings/Validation Rules/Item Rules
Important: Make sure you populate the
Type
field with your fully-qualified name of your custom validator's class (e.g.Custom.Services.AtLeastOneFieldPopulatedValidator, Custom.Services
).
3. Associate your Validation Rule
to your items
On the __Standard values
of your item's template, show Standard Fields (View ribbon tab -> Standard fields) and add your Validation Rule
to the appropriate validation fields. I recommend including it in all four.
(Optional) Extra credit: Add parameters
I've not tested this, but I'm sure there's a way to pass parameters using the Parameters
field on the Validation Rule
item. In these parameters, you could pass a list of the fields to check so your validator can be reused by creating multiple Validation Rule
items in Sitecore.
edited Jan 7 at 18:33
answered Jan 7 at 16:21
Dan SinclairDan Sinclair
2,188627
2,188627
did you test this code? It would be great if it works but my understanding is that item["Field 2"] would not have a value at the point the validation for item["Field 1"] fires. This is mentioned in the SSE posts I've referenced in my answer.
– Adam Seabridge
Jan 7 at 18:19
I believe this will be different, however, because this is an Item validator (not a field validator). I believe it still runs after every field is updated (I haven't dug through the CE JS to verify that), but it validates the entire item instead of just a single field.
– Dan Sinclair
Jan 7 at 18:23
It also appears this is the same solution they used in the second SSE post you linked: "We additionally put an item validator on the component itself to prevent it from going through workflow."
– Dan Sinclair
Jan 7 at 18:25
Ahr right, sorry yes it's not a field validator so the values should both be set. No worries then.
– Adam Seabridge
Jan 7 at 18:30
@AdamSeabridge you point out a valid concern, though, that it was not clear. I've edited the answer to attempt to call that out more clearly.
– Dan Sinclair
Jan 7 at 18:34
|
show 6 more comments
did you test this code? It would be great if it works but my understanding is that item["Field 2"] would not have a value at the point the validation for item["Field 1"] fires. This is mentioned in the SSE posts I've referenced in my answer.
– Adam Seabridge
Jan 7 at 18:19
I believe this will be different, however, because this is an Item validator (not a field validator). I believe it still runs after every field is updated (I haven't dug through the CE JS to verify that), but it validates the entire item instead of just a single field.
– Dan Sinclair
Jan 7 at 18:23
It also appears this is the same solution they used in the second SSE post you linked: "We additionally put an item validator on the component itself to prevent it from going through workflow."
– Dan Sinclair
Jan 7 at 18:25
Ahr right, sorry yes it's not a field validator so the values should both be set. No worries then.
– Adam Seabridge
Jan 7 at 18:30
@AdamSeabridge you point out a valid concern, though, that it was not clear. I've edited the answer to attempt to call that out more clearly.
– Dan Sinclair
Jan 7 at 18:34
did you test this code? It would be great if it works but my understanding is that item["Field 2"] would not have a value at the point the validation for item["Field 1"] fires. This is mentioned in the SSE posts I've referenced in my answer.
– Adam Seabridge
Jan 7 at 18:19
did you test this code? It would be great if it works but my understanding is that item["Field 2"] would not have a value at the point the validation for item["Field 1"] fires. This is mentioned in the SSE posts I've referenced in my answer.
– Adam Seabridge
Jan 7 at 18:19
I believe this will be different, however, because this is an Item validator (not a field validator). I believe it still runs after every field is updated (I haven't dug through the CE JS to verify that), but it validates the entire item instead of just a single field.
– Dan Sinclair
Jan 7 at 18:23
I believe this will be different, however, because this is an Item validator (not a field validator). I believe it still runs after every field is updated (I haven't dug through the CE JS to verify that), but it validates the entire item instead of just a single field.
– Dan Sinclair
Jan 7 at 18:23
It also appears this is the same solution they used in the second SSE post you linked: "We additionally put an item validator on the component itself to prevent it from going through workflow."
– Dan Sinclair
Jan 7 at 18:25
It also appears this is the same solution they used in the second SSE post you linked: "We additionally put an item validator on the component itself to prevent it from going through workflow."
– Dan Sinclair
Jan 7 at 18:25
Ahr right, sorry yes it's not a field validator so the values should both be set. No worries then.
– Adam Seabridge
Jan 7 at 18:30
Ahr right, sorry yes it's not a field validator so the values should both be set. No worries then.
– Adam Seabridge
Jan 7 at 18:30
@AdamSeabridge you point out a valid concern, though, that it was not clear. I've edited the answer to attempt to call that out more clearly.
– Dan Sinclair
Jan 7 at 18:34
@AdamSeabridge you point out a valid concern, though, that it was not clear. I've edited the answer to attempt to call that out more clearly.
– Dan Sinclair
Jan 7 at 18:34
|
show 6 more comments
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%2f15890%2fmake-one-of-two-sitecore-content-fields-required%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
Nothing OOTB, but there may be a way to achieve what you are looking for via breaking up your content appropriately into different templates. For example, if you have two datasource templates, you could have different rules for validation. The author picks which template they want to use by selecting compatible renderings. It may help to know more about your specific authoring scenario to help guide you.
– Jason St-Cyr
Jan 7 at 15:23