field validation

Posted by Community Admin on 03-Aug-2018 01:54

field validation

All Replies

Posted by Community Admin on 14-Jun-2011 00:00

I have a text field that I would like validate the min and max values for but it is throwing the error "Cannot convert from string". How do I specify the min and max values?

<sitefinity:TextField ID="subscriberLimit" runat="server" 
                        DisplayMode="Write" 
                        Title='<%$Resources:CampaignsResources, SubscriberLimit %>' 
                        Description='<%$Resources:CampaignsResources, SubscriberLimitDescription %>'
                        WrapperTag="Li">
    <ValidatorDefinition Required="false" MessageCssClass="sfError"
                        ExpectedFormat="Integer"
                        MinValue="1"
                        MaxValue="99999"  />
</sitefinity:TextField>

I also have a date field that I would like displayed in the format dd/MM/yyyy. I tried setting the dataformat property but that didn't help. How do I specify the date format?

<sitefinity:DateField ID="startDate" runat="server" 
                        DisplayMode="Write" 
                        Title='<%$Resources:CampaignsResources, StartDate %>' 
                        Description='<%$Resources:CampaignsResources, StartDateDescription %>'
                        WrapperTag="Li" DataFormat="dd/MM/yyyy h:mm:ss">
    <ValidatorDefinition Required="true" MessageCssClass="sfError" />
</sitefinity:DateField>


Cheers,

Brian

Posted by Community Admin on 14-Jun-2011 00:00

Hello Brian Crosby,

 From the error that you are receiving I assume that you are using the validation on the server. If this is the case I have to inform you that the default Validator doesn't support min/max validating of field controls that work with string values even if you have set the expected format to be Integer. Could you provide more info on your usage scenario so that I can think of a suitable workaround. The information I need is where are you using those field controls how do you validate them etc.

Kind regards,
Momchil Mitev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 14-Jun-2011 00:00

Hi Brian Crosby,

 About the DateField you can take a look at the following forum thread:
http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/event-time-picker---12-hour-format.aspx
It describes how can you set the date picker to a 12 hour format. The property you need is located here:

...
this._datePicker = jQuery("#" + this._datePickerId).datetimepicker(
                    dateFormat: "mm/dd/yy",
                    timeFormat: "hh:mm:ss",
                    hourGrid: 4,
                    minuteGrid: 10,
                    beforeShow: popupOpeningDelegate,
                    onClose: popupClosedDelegate,
                    showOn: "focus",
                    ampm: true
                );
...

This is just an extract of the code you need to copy paste, highlighting the location of the properties you need.


All the best,
Momchil Mitev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 15-Jun-2011 00:00

Hello Momchil Mitev,

I am using the control in a custom module. The validation needs to happen on the client side. I tried setting the min and max values in the code behind but it didn't trigger the validator. I did see the min and max values in the outputted validator javascript though. Does the min and max even work for the validator?

I added a regex which works but I want the field to be optional and the regex is causing a validation error on an empty textbox. 


Posted by Community Admin on 15-Jun-2011 00:00

Hi Brian Crosby,

 The reason behind this behaviour is that the regex check is applied even if the string is empty. This is a bug which is fixed and will be available in the next SP release.
Since you have already developed such regex the fastest workaround would be to modify it to allow empty strings like this:
"^(<your custom regex expression>])0,1$"

All the best,
Momchil Mitev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 15-Jun-2011 00:00

Hello Brian Crosby,

I have left an unnecessary character in the regex example. The correct one is this:
"^(<your custom regex expression>)0,1$"

Regards,
Momchil Mitev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed