CustomValidator and Advanced Modal forms

8 posts, 1 answers
  1. Ilya
    Ilya avatar
    67 posts
    Member since:
    Jul 2012

    Posted 12 Sep 2011 Link to this post

    I am having difficulties integrating CustomValidators on the Advanced Insert and Edit forms. By difficulties I mean that they simply don't work. Did anybody encounter similar problems? What is the solution? Thanks
  2. Ilya
    Ilya avatar
    67 posts
    Member since:
    Jul 2012

    Posted 14 Sep 2011 Link to this post

    Bump
  3. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 14 Sep 2011 Link to this post

    Hi Ilya,

    The help article on the link given bellow explains how to add a custom validator to the description field in the AvancedForm:
    Customizing the Advanced Form: Handling Form Created.

    Look for "Add a new custom validator for the description field" at the bottom of the page.

    Greetings,
    Ivana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
  4. Ilya
    Ilya avatar
    67 posts
    Member since:
    Jul 2012

    Posted 15 Sep 2011 Link to this post

    Hi Ivana,

    Ok, I am still having difficulties with CustomValidator. Basically I have a RadNumericTextBox field where the recurrence interval is to be entered and series of checkboxes for days for the week. If they check one of the checkboxes and forget to enter interval I want to display an error message. Here is the code I am trying to integrate:

    <table cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td colspan="4" style="font-family: Arial; font-size: 8pt; padding-left: 5px; width: 100%;">
    Recur every
    <telerik:RadNumericTextBox ID="txtRecInterval" runat="server"
    Type="Number"
    ShowSpinButtons="True"
    NumberFormat-DecimalDigits="0"
    MinValue="1"
    Width="50px"
    Height="10"
    TabIndex="10">
    </telerik:RadNumericTextBox>
    week(s) on
    </td>
    </tr>
    <tr>
    <td>
    <asp:CheckBox ID="chkRecMon" runat="server" Width="20px" /><span style="vertical-align: sub; font-family: Arial; font-size: 8pt;">Monday</span>
    </td>
    <td style="padding-left: 5px;">
    <asp:CheckBox ID="chkRecTue" runat="server" Width="20px" /><span style="vertical-align: sub; font-family: Arial; font-size: 8pt;">Tuesday</span>
    </td>
    <td style="padding-left: 5px;">
    <asp:CheckBox ID="chkRecWed" runat="server" Width="20px" /><span style="vertical-align: sub; font-family: Arial; font-size: 8pt;">Wednesday</span>
    </td>
    <td style="padding-left: 5px;">
     <asp:CheckBox ID="chkRecThu" runat="server" Width="20px" /><span style="vertical-align: sub; font-family: Arial; font-size: 8pt;">Thursday</span>
     </td>
    </tr>
    <tr>
    <td>
    <asp:CheckBox ID="chkRecFri" runat="server" Width="20px" /><span style="vertical-align: sub; font-family: Arial; font-size: 8pt;">Friday</span>
    </td>
    <td style="padding-left: 5px;">
    <asp:CheckBox ID="chkRecSat" runat="server" Width="20px" /><span style="vertical-align: sub; font-family: Arial; font-size: 8pt;">Saturday</span>
    </td>
    <td style="padding-left: 5px;">
    <asp:CheckBox ID="chkRecSun" runat="server" Width="20px" /><span style="vertical-align: sub; font-family: Arial; font-size: 8pt;">Sunday</span>
    </td>
    <td>
    <asp:CustomValidator ID="cval1" runat="server" ErrorMessage="Please enter Interval!" ControlToValidate="txtRecInterval"
     ClientValidationFunction="validationFunction" SetFocusOnError="true"></asp:CustomValidator>
    </td>
    </tr>
    <tr>
    <td colspan="4" style="height: 10px; vertical-align: middle; width: 100%;">
    <hr style="width : 282px;" />
    </td>
    </tr>
    </table>

    And here is the Javascript:

    <script type="text/javascript">
    function validationFunction(source, arguments) {
    chkMon = document.getElementById("chkRecMon")
    chkTue = document.getElementById("chkRecTue")
    chkWed = document.getElementById("chkRecWed")
    chkThu = document.getElementById("chkRecThu")
    chkFri = document.getElementById("chkRecFri")
    chkSat = document.getElementById("chkRecSat")
    chkSun = document.getElementById("chkRecSun")
     interval = arguments.Value.length
     if (chkMon.checked && interval > 0 || chkTue.checked && interval > 0 || chkWed.checked && interval > 0 || chkThu.checked && interval > 0 || chkFri.checked && interval > 0 || chkSat.checked && interval > 0 || chkSun.checked && interval > 0) {
     arguments.IsValid = true;
    } else {
    arguments.IsValid = false;
    }
    }
    </script>

  5. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 19 Sep 2011 Link to this post

    Hi Ilya,

    In order to validate an empty text using CustomValidator you have to set the ValidateEmptyText property of the CustomValidator to true.

    I have made an example page (using the code you sent) showing how you could do the validation for the RadNumericTextBox.

    Attached is only the .aspx file.

    I hope this helps.

    Best wishes,
    Ivana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
  6. Ilya
    Ilya avatar
    67 posts
    Member since:
    Jul 2012

    Posted 19 Sep 2011 Link to this post

    Hi Ivana,

    Unfortunately its still does not work. I have custom validators on many other pages and they work. Your demo also works but the issue I am having is when the customvalidator is located inside the AdvancedInsert or AsdvancedEdit forms of RadScheduler. As soon as I add CustomValidator to AdvancedInsert form and click Submit button all other validators stop working (that normally work) and page is submitted. This happened before and it is happening with your code as well.
  7. Answer
    Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 20 Sep 2011 Link to this post

    Hi Ilya,

    I have tested your scenario in the AdvancedForm of the RadScheduler.

    In order to make the CustomValidator to work in the AdvancedForm a validation group should be set.
    Example C#:
    cval1.ValidationGroup = Owner.ValidationGroup;

    Also I have made some changes in the ClientValidationFunction.
    JavaScript:
    function validationFunction(source, arguments) {
                var jQueryMon = $telerik.$("[id$='_chkRecMon']");
                var jQueryTue = $telerik.$("[id$='_chkRecTue']");
                var jQueryWed = $telerik.$("[id$='_chkRecWed']");
                var jQueryThu = $telerik.$("[id$='_chkRecThu']");
                var jQueryFri = $telerik.$("[id$='_chkRecFri']");
                var jQuerySat = $telerik.$("[id$='_chkRecSat']");
                var jQuerySun = $telerik.$("[id$='_chkRecSun']");
     
                var isDayChecked = (jQueryMon.attr("checked") || jQueryTue.attr("checked") || jQueryWed.attr("checked")
                    || jQueryThu.attr("checked") || jQueryFri.attr("checked") || jQuerySat.attr("checked") || jQuerySun.attr("checked"));
     
                var interval = arguments.Value.length;
                if (isDayChecked && interval > 0) {
                    arguments.IsValid = true;
                } else if (!isDayChecked && interval > 0) {
                    source.innerHTML = "Please insert a recurrence day";
                    arguments.IsValid = false;
                } else if (isDayChecked && interval == 0) {
                    source.innerHTML = "Please insert a recurrence interval";
                    arguments.IsValid = false;
                }
            }

    Hope this workaround works for you.

    All the best,
    Ivana
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  8. Ilya
    Ilya avatar
    67 posts
    Member since:
    Jul 2012

    Posted 20 Sep 2011 Link to this post

    Ivana,

    Ok, it works, even without setting the ValidationGroup property. I think it was an issue of Javascript finding the controls on the page. Thank you very much for your help.
Back to Top