This is a migrated thread and some comments may be shown as answers.

Scheduler as SharePoint web part - validation

2 Answers 28 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 01 Dec 2016, 11:17 AM

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 Answers, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 06 Dec 2016, 07:43 AM
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.
0
Jonathan
Top achievements
Rank 1
answered on 08 Dec 2016, 12:34 PM
Thanks Plamen. Pretty obvious really when it's pointed out!
Tags
Scheduler
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Jonathan
Top achievements
Rank 1
Share this question
or