I have done a lot of fancy validations client side using the JQuery Validate 
library (http://jqueryvalidation.org/)
I know its not really ideal, but I have gotten reference to the controls I am 
validating via their display name. The following code shows how I:create my own 
validation method to check if an end date is greater than a start dataget the 
date fieldssetup the validatoradd the validation rules to the date fields
jQuery(document).ready(function () {
            // Validation function 'Greater Than'            
jQuery.validator.addMethod("greaterThan",                function (value, 
element, params) {                    if (!/Invalid|NaN/.test(new Date(value))) 
{                        var splitter = value.split("/");                       
 var greaterDate = new Date(splitter[2], splitter[1] - 1, splitter[0]);         
               splitter = jQuery(params).val().split("/");                      
  var lesserDate = new Date(splitter[2], splitter[1] - 1, splitter[0]);
                        return greaterDate > lesserDate;                    }   
                 return isNaN(value) && isNaN(jQuery(params).val())             
         || (Number(value) > Number(jQuery(params).val()));                }, 
'Must be greater than {0}.');
            // Fields to be validated            var plannedEnd = 
jQuery("input[title='Planned End']");            var plannedStart = 
jQuery("input[title='Planned Start']");
            // validate form on keyup and submit            
jQuery("#aspnetForm").validate({                errorClass: 
"ms-formvalidation",                onsubmit: false,                
errorPlacement: function (error, element) {                    
error.appendTo(element.parent("td").next("td"));                }            });
            plannedEnd.rules('add', {                required: true,            
    messages: {                    required: "You must specify a value for 
\'Planned End\'."                }            });
            plannedEnd.rules('add', {                required: true,            
    greaterThan: "input[title='Planned Start']",                messages: {     
               greaterThan: "\'Planned End\' must occur on or after \'Planned 
Start\'"                }            });        });

From: [email protected]
Date: Fri, 19 Jul 2013 16:44:39 +1200
Subject: Re: SharePoint date time control
To: [email protected]

I used ID the way you are suggesting, and it works for textboxes, radio buttons 
but not for DTC
doing more digging I found that 
The DTC has got text box and to get the value of the text box.. we have to use  
dtcdeadline$dtcdeadlineDate 


By using dtcdeadline$dtcdeadlineDate, the required field validators work, but 
this scenario of using it in CompareValidator is not working

I had to use the above double ID value in controToValidate property for 
required field validator, which works fine





On Fri, Jul 19, 2013 at 4:06 PM, Ishai Sagi <[email protected]> wrote:










For example:
 
<sharepoint:datetimecontrol runat=”server” id=”dtcDeadline” />
 
<script>
Var d = document.getElementByID(“<%=dtcDeadline.ClientID %>”);
</script>
 
Ishai
 Sagi |
Solutions Architect


0488 789 786
|
[email protected]
|
www.sharepoint-tips.com
|
@ishaisagi
|
MVP Profile 

 
From: [email protected] [mailto:[email protected]]
On Behalf Of Ajay

Sent: Friday, 19 July 2013 1:59 PM

To: ozMOSS

Subject: SharePoint date time control
 




I  have to validate date time control, if it has any value and based on that 
allow a another field to be blank or not.

The text box for dtc is referenced by dtcDeadline$dtcdeadlineDate


following line does not look good


 


var deadlineDate = 
document.getElementById('<%=dtcDeadline$dtcdeadlineDate.ClientID%>');


 

 

Am I missing some easy fix for this...



Cheers

ajay




 









_______________________________________________

ozmoss mailing list

[email protected]

http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss





_______________________________________________
ozmoss mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss                           
          

<<inline: image002.jpg>>

_______________________________________________
ozmoss mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss

Reply via email to