Scheduler as SharePoint web part - validation

3 posts, 1 answers
  1. Jonathan Simmons
    Jonathan Simmons avatar
    108 posts
    Member since:
    Jun 2005

    Posted 01 Dec 2016 Link to this post

    Hi, I have created a custom SharePoint 2010 web part using a scheduler with some custom attributes. Everything is working fine except for validation of the custom attributes on the advanced edit/insert form. There are two text boxes which should not be empty and save should not allow the advanced form to be saved back to the SP list. 

    I have the following code in the FormCreated event:

    RadScheduler scheduler = (RadScheduler)sender;
     
    CustomValidator validatorForAttributePhone = new CustomValidator();
    validatorForAttributePhone.ValidationGroup = scheduler.ValidationGroup;
    validatorForAttributePhone.ControlToValidate = "AttrPhone";
    validatorForAttributePhone.ErrorMessage = "Cannot be blank!";
    validatorForAttributePhone.ClientValidationFunction = "validationFunctionPhone";
    (e.Container.FindControl("AttrPhone") as RadTextBox).Parent.Controls.Add(validatorForAttributePhone);

     

    And the jsavascript function is 

    function validationFunctionPhone(source, arguments)
    {
      if (arguments.Value.length != 0)

      { arguments.IsValid = true; }

      else {arguments.IsValid = false}
    }

     

    All the validation seems to be created OK but this never fires when the 'Save' button is clicked on the advanced edit/insert form which means that the appointment can be saved when there is no text in the phone field on the form.

    What am I missing?

    Thanks,

    Jonathan

     

  2. Answer
    Plamen
    Admin
    Plamen avatar
    2753 posts

    Posted 06 Dec 2016 Link to this post

    Hi,

    In such case when you need do check if the field is filled you should use the RequiredFieldValidator as for example it is done in the code below:
    RequiredFieldValidator validatorForAttributePhone = new RequiredFieldValidator();
          validatorForAttributePhone.ValidationGroup = scheduler.ValidationGroup;
          validatorForAttributePhone.ControlToValidate = "AttrPhone";
          validatorForAttributePhone.ErrorMessage = "Cannot be blank!";
          (e.Container.FindControl("AttrPhone") as RadTextBox).Parent.Controls.Add(validatorForAttributePhone);


    Regards,
    Plamen
    Telerik by Progress
    Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
  3. Jonathan Simmons
    Jonathan Simmons avatar
    108 posts
    Member since:
    Jun 2005

    Posted 08 Dec 2016 in reply to Plamen Link to this post

    Thanks Plamen. Pretty obvious really when it's pointed out!
Back to Top