locked
Form validation RRS feed

  • Question

  • i have created a list which has 2 columns Title and Birthday. I want to apply required field validation on Birthday field. For this I have written jquery code and pushed it into the Content Editor web Part.  Validation is done at client side.

    The issue is that validation is happening but the error message (which should be displayed if field left empty) is not getting displayed. I guess it is hiding somewhere behind the sharepoint date time picker calendar adjacent to the Birthday field, Because when i run the same query for some other field say location field whose type is string then the  errror message specified become visible.

    Also when i view the page source. Save the file as html and then open the html file. In that case when i donot enter anything then the calendar gets shifted to the right and error message "Please enter some date"  is displayed. So i think there is no problem with the correctness of the jquery. The Problem is the not seeing the error message because somehow it gets hidden behind the calendar or calendar doesnot allow it to be displayed.

    Please Help! Here is my code.

    i Hve included js file from docs.jquery.com for using standard function like required:true

    $(document).ready(function() {  

    $('#aspnetForm').validate({ 

    submitHandler: function(aspnetForm) { }

                                         });  

    $("input[title='BirthDate']").rules('add',{ 

    required: true, 

    messages: {  required: 'please enter some date.' }  });

      $("input[value='Save']").focus(function(){ 

    $("input[title='BirthDate']").valid();

    if (!$("input[title='BirthDate']").valid()  )

    {  alert('Please enter the required fields.'); 

    $("input[title='BirthDate']").focus();  }  }); 

     });

    Wednesday, May 25, 2011 1:42 PM

Answers

  • For that kind of validation, yes you can use javascript. In your first post you mentioned the validation is happening but the error message is not showing up. That depends on how you're showing the message. You may need to use appropriate CSS to display the message or you can just use javascript alerts.

    Since you're using SharePoint 2010, this isn't the correct forum. Below is the link to the 2010 forum. Just wait till a moderator moves your post. You may get better solution/advise from there.

    http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010customization/threads

     


    Pman
    http://www.pmansLab.com/
    • Marked as answer by Peng Lei Wednesday, June 1, 2011 3:04 AM
    Friday, May 27, 2011 1:35 AM

All replies

  • What's your validation requirement? If it's just to make sure that the field is not empty, can you not change the column setting from the List settings page? Just set the column as "Required" and sharepoint will take care of the rest automatically.

    By the way, what version of sharepoint are you working with?

     


    Pman
    http://www.pmansLab.com/
    Thursday, May 26, 2011 1:08 AM
  • Hi,

    I am using SharePoint 2010.

    Yes you are absolutely right that one can apply required field validation by going to settings page and making that field required.

    But I have to apply other types of validation also like range validation (i,e date has to been in certain range otherwise the specified error message is displayed). Sometime it is required to apply multiple validatons simultaneously ( like required field and range ).

    The problem is tha each validation ( required field, range) is happening properly (i.e form is not getting submitted if validaiton fails) but the corresponding error message is not getting displayed. 

    While for other fields like Email whose datatype is string the validation is happening and error message is also getting displayed.

    Is there a way to change the location of error message which gets generated when validation fails. 

    Thursday, May 26, 2011 10:20 AM
  • For that kind of validation, yes you can use javascript. In your first post you mentioned the validation is happening but the error message is not showing up. That depends on how you're showing the message. You may need to use appropriate CSS to display the message or you can just use javascript alerts.

    Since you're using SharePoint 2010, this isn't the correct forum. Below is the link to the 2010 forum. Just wait till a moderator moves your post. You may get better solution/advise from there.

    http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010customization/threads

     


    Pman
    http://www.pmansLab.com/
    • Marked as answer by Peng Lei Wednesday, June 1, 2011 3:04 AM
    Friday, May 27, 2011 1:35 AM