Apply Sitecore validation rule to a field type? - validation

I have created a validation rule in Core DB, and I have created a custom Sitecore field called 'Single Select Treelist'. I want to apply this validation rule to all 'Single Select Treelist' fields in all templates in my Sitecore instance.
I know we can individually apply the validation rule to each template field of type 'Single Select Treelist'. Is there a way to achieve this automatically for all 'Single Select Treelist' fields without any custom coding?
I see the list of field type validation rules available in Master:
How are these connected to the respective field types in Core?
Please advise.

If you edit the field type item there is a validation section that contains fields to set validation rules for the Quick Action Bar, the Validate Button, the Validator Bar and finally Workflow.
Once you set the validation rules, depending on which field you set, Sitecore will display the validation messages in different ways. See this blog post for examples: http://sitecoreworld.blogspot.com/2014/12/sitecore-validation-examples.html

The link between the Field Type Validation Rule and the actual Field Type seems to be based simply on the name of the Field Type.
Just add a new item with the template "Field Type Validation Rules" in the Validation Rules/Field Types folder that you show in your picture. Give it the exact same name as the field type you want it to validate. Select the rules you need inside the Validation Rules section of that new object.
For example, I just needed to add some validation to the Single-Line Text type, as you can see in the image. We struggled with it for a little while because we missed the dash.
Image - Sitecore Tree with new Field Type Validation

Related

Business rule: Add other field value to date?

I'm trying to programmatically set the Due Date field of a custom activity. I want take the value of another date-time field that the users enters and add the value from an integer field. But it seems that I can only select a static value to add using the business rules as shown here:
Is there a way to do it using business rules? Or do I have to use a Javascript instead?
You can use calculated field for these scenarios, but it is not a physical field to store. If you have to store the value, then Javascript or plugin or WF is better.
Business rules are limited in these situations.
This should be quite easy using PowerApps expression language; no need for PowerApps "Rules" (which are slated to be deprecated).
To your app:
Add a DatePicker control
Add a TextBox control
Add a Label control
Set the Label control's Text property to:
DateAdd(
DatePicker.Selected.Value,
Value(TextBox.Text),
Days
)
Bingo!

Laravel 5.2 different validation rules based on another field value inside request class

Here is what I'm trying to accomplish, I have a form that has a dropdown field of types, lets say type1, type2, type3, and I have a textfield, I want to make the rule for the textfield depend on the type, for example if the type is type1 then the validation rule for the value of the textfield should be 'email' if it is type2 then the validation rule is 'number', etc.
I have read the Validation documentation on the Laravel site, I know this section is what I'm trying to accomplish, but I like to keep validation logic separate from the controller, and it doesn't say how to call the sometimes method from within the request class.

Joomla Component Dynamic Custom Field based on other Field Value

I am creating a new Joomla Component. I am able to create custom fields for the component backend forms - but I am not able to create Dynamic Custom Fields.
What I would like to do is have a field that is dynamical populated based on the value of a previous field. The easiest way to explain this is the simple country,state,city breakdown.
Field 1 = Country
Field 2 = State (Based on what the user selected as as Country in Field 1)
Field 3 = City (Based on what the user selected as State in Field 2)
The fields would of course need to be refreshed, reset as the user picks a different country etc.
The data to populate the fields would also all need to come from a database based on the previous fields value.
I am guessing this needs to be done via ajax or javascript or something? But wondering if there is an official way? Especially since there are database calls involved.
Please let me know if there is anything I can explain better..
David
I ended up just creating text fields but then validating the input to make sure the values added are correct.

Different validation on a field depending on user selection

For example lets say I have the following validator:
Acme\BlogBundle\Entity\Person:
properties:
ID:
- NotBlank: ~
However the kind of validation for ID depends on the property IDType that is selected by a user. Which some IDS can be blank and some cannot. Not only that but other types of ID needs other types of validation. Is this possible to do? Or should I have one property for each ID?
The Callback validation constraint is very suitable in this case. It lets you define complex validation logic and add errors to any form field you see fit.

Throwing a message when Updating/Validating Part contents/data

Crosspost: https://orchard.codeplex.com/discussions/455498
When updating a Part, in the DriverResult Editor, how can we manually throw a warning message when implementing custom validation?
I want to add a custom validation for some date fields, where values are dependent on some other field in the Content Item itself (dates in the part need to be between a specific date in the content item's field).
Which leads me to another question, can we set validation in model properties between one another? Like if there are two properties StartDate and EndDate, is it doable in the model to declare that end date must be after start date?
You can add model validation errors using the "updater" parameter being passed in:
updater.AddModelError("StartDate", T("Please enter a date in the future"));

Resources