This seems like a really simple task to accomplish, but I can't seem to figure it out. How do you assign validation to a particular field in Sitecore?
I can see the validation rules listed in /sitecore/system/Settings/Validation Rules/Field Rules/.
How do I assign a rule from here to a field on a template?
I've seen several blog posts about creating a custom OnSave action that evaluations the item and it's fields - that you then hook up in the web config - but that is way overkill for what I'm trying to accomplish. None of the blog posts or pdfs from Sitecore itself seem to show how to set up really simple validation (or I can't find them).
For some basic validation you can browse to your template, select the field itself (the field item underneath the template, I mean) and browse to the Validation Rules section.
There is also another simple way (did not check if it stil exists in Sitecore 7).
Go to the template field itself, as Trayek says, and therer you have 2 fields: "Validation" and "ValidationText".
In Validation you enter the regex for the validation and in ValidationText you enter the text to display.
Just set validation rule Item id in Suppressed Validation Rules field.
First check the "Standard Fields" checkbox from "view" tab of top ribbon and go on data template of selected item, select field for validation, on this field you can find Validation Rules bar here you can apply validation.
I would not just dump a regex in the validation field. Creating a rule and assigning it on a template affords you a lot more flexability
Related
I'm doing some work in ASP.Net MVC(First work. Not expert in jquery). Until now [Required/Rage etc.] attribute was enough for completing my requirement. Now I need to return Required attributing conditionally. I checked lots of posts like this
I gone through IValidatableObject but it's not returning the javascript automatically. Then i went through requiredif it needs a lot of work to implement(all the scripts we only need to generate)
So is there a simple way like enabling/disabling required/Range etc attributes conditionally(on a switch)?
Editing
In my project I have multiple tabs(some will be invisible). I'm getting validation errors of the invisible tabs. So I'm planning to give validation if the visibility of the tab is true
How can I get my CheckBoxList to have three possible states ? More precisely, is there a way to have three possible states for each checkbox : checked, unchecked, undefined (in most GUIs this is represented as a full square).
Alternatively, do you recommend another control that would meet these needs ?
UPDATE : Ok, given that HTML does not support tri-state checkboxes, I'm looking for a way to 'CSS' (color fill, highlight, etc...) the checkboxes of the items that are in that 'undefined' state from my server point of view.
Not all GUIs represent undefined as a full square. That's why it's going to be clearer to use one of the following:
1. Radio boxes
2. Dropdown
3. ListBox
Any asp.net control you use will ultimately need to be rendered as an html checkbox, which can only be checked or unchecked. You could use a data- attribute to keep track of extra state behind the scenes, but that wouldn't be reflected in the UI.
I suppose you could also implement a client-side solution using JavaScript and CSS as well.
You could just extend or derive from the CheckBoxList and create your own custom control from it.
Here is an example of this.
Custom CheckBoxList
I have decided to use CheckBoxList anyway, since I need two states accessible by the user, and a third one not accessible by the user but to display inconsistencies.
The way I have solved this is through Javascript + CSS. Some bits of ideas here: http://css-tricks.com/indeterminate-checkboxes/
I have a telerik combobox in mvc3 application and I want to prevent the user writing a value different from the list being loaded from the controller.
A thing that partial helped is to set the textbox input to be readonly but then:
1. The user can filter the list by the textbox.
2. The user can erase his selection.
Another thing that I thought about is: What the user types in the select is the value not the description, so I need it to prevent writing text different from the description while the value remains encapsulated.
Are you still looking to have the user be able to input custom text? If not you can use the DropDownList functionality as seen on this demo page.
If you still want the user to be able to type into the component but somehow have it aware of when they either misspell something, or type one character more than necessary, this can be extremely difficult. You would essentially have to have some clever JavaScript to be triggered with every key press and check the current value against a list. With users being pretty quick with typing, or their browsers being old, this can be very unreliable. Plus, a user can easily disable JavaScript at any time making this functionality obsolete.
I think your best options is to have it as is, where the user can type whatever they want. You can always have validation on the item they have typed and upon blur() or a POST (whatever fits your application) have a message appear to warn them of an invalid entry.
Ok, let me try to clearly explain what I'm attempting to accomplish here.
Basically, I have a site that is using a liberal dose of jquery to retrieve partialviews into a consolidated 'single view'. So far so good - it all works great and is very performant.
However, I would like to have the ability to 'flag' (using a button) any such set and as a consequence of flagging it, add it to a functional area that I have dubbed 'active-tasks'. What I'd like to do is to be able to then goto that 'active-tasks' panel and see a range of ui tabs that represented the consolidated views that I had added. Clicking on any tab would then re-invoke that consolodated view afresh with the parameters that had been used at the time of flagging it. This would therefore mean that I'd have to store the parameters (?) for creating that consolidated view, rather than the generated html (this part i can do at the moment).
So, any thoughts on how to elegantly store the code required to generate the consolidated view on clicking a tab button - no pressure :)
cheers - jim
Actually, after a minimal amount of research, it looks like the newly updated .data() jquery method (with the ability to add an object to the payload) may work for the above.
http://api.jquery.com/data/
basically, this allows you to add hash type keyed data to an id element for use later, so in my scenario above i could simply attach the parameters required to invoke the action method that related to my consolidated view on the tab.
I'll let you know how i progress with this...
jim
how to validate the input form of a silverlight control?
I have 3 controls, two out of three are text boxes (For name, and Age), and the remaining one control is date picker.
When i hit submit button, the validation should be invoked. how it will done??
thanks in advance.
If you're using Silverlight 3 check out Data Validation. http://www.silverlightshow.net/items/Data-Validation-in-Silverlight-3.aspx
If you're using Silverlight 2 you'll have to roll your own code for validation.
I wrote my own validaion for SL2. It's based on:
Attached property to give control custom validation ID
Business object validators that identify invalid data
VisualTreeHelper to parse visual tree and match validation result and custom validation ID
Custom templates for controls in order to display validation
INotifyPropertyChanged to remove validation display if property value was changed.
You may also find the Validation Application Block (which is part of the Enterprise Library Silverlight Integration Pack) useful. It's in public preview right now.