1

I have a form with a dynamically generated people picker control, that is required if the checkbox above it is selected(not required otherwise)

This is how I created the control.

var people = new Microsoft.SharePoint.WebControls.PeopleEditor { ID = "PeoplePicker2" ,
                                                                  AllowEmpty = false,ValidatorEnabled = true};

Here is the validator

 divppAO2.Controls.Add(new RequiredFieldValidator
        {
            ID = "PplPkrR2fv",
            ControlToValidate = people.ID,
            ErrorMessage =
                "You must specify a value for this required field.",
            Display = ValidatorDisplay.Dynamic,
            Enabled = false
        });

The problem comes when I try to call ValidatorEnable jquery function on this validator.

 checkBoxes.change(function () {
            var current = $(this),
                isChecked = current.prop('checked'),
                td = current.closest('td'),                    
                pplvalidators = td.find('span[id*="PplPkr"]');                  

            validators.each(function () {
                ValidatorEnable($(this).get(0), isChecked);
            });

This does seem to toggle the display of the required field message.But when I uncheck the checkbox and submit the form, form does not get submitted. It still shows the required field error message. Where am I going wrong? Please help.Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.