Validate resource only if boolean attribute is true

7 posts, 0 answers
  1. Jill-Connie Lorentsen
    Jill-Connie Lorentsen avatar
    118 posts
    Member since:
    Nov 2008

    Posted 18 Apr 2013 Link to this post

    I have a scheduler with a customized advanced form. On this form I have a Boolean attribute control ResFlight, indicating whether the appointment is a flight, and a resource contol ResAirport holding the departing airport.

    If the user checks the ResFlight checkbox I want the ResAirport to be required. 

    I would like to do this on the client, but I am a bit lost. I've tried using the asp validators, but I get an error saying that the ResAirport is "an invalid control to validate type"

    Any ideas?


    Regards, Jill-Connie Lorentsen
  2. Plamen
    Admin
    Plamen avatar
    3079 posts

    Posted 23 Apr 2013 Link to this post

    Hello Jill,

     
    Here is the mark up that makes the CustomValidator validate the resource RadCombobox:

    <asp:CustomValidator runat="server" ID="RequiredFieldValidator1" ClientValidationFunction="clientValidationFunction"
                                 ControlToValidate="ResRoom$ResourceValue" ErrorMessage="Select from combo" OnServerValidate="RequiredFieldValidator1_ServerValidate" 
                           EnableClientScript="true" Display="None" CssClass="rsValidatorMsg" />

    From here you can use either the serve or the client event to validate the control according to your requirements.

    Hope this will be helpful


    Regards,
    Plamen
    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.
  3. Jill-Connie Lorentsen
    Jill-Connie Lorentsen avatar
    118 posts
    Member since:
    Nov 2008

    Posted 25 Apr 2013 Link to this post

    Thank you for your reply, but still some details are missing.

    My markup is like this:
    <scheduler:BooleanAttributeControl runat="server" ID="ResFlight" Type="Flight" Label="Flight: "  Skin='<%# Owner.Skin %>' Checked='<%# Eval("Flight") %>'  Value="false" />
                                     
    <scheduler:ResourceControl ID="ResAirport" runat="server" Type="Airport" Required="false" Label="Airport: " Skin='<%# Owner.Skin %>' />
                                         
                                     
    <asp:CustomValidator runat="server" ID="AirportRequiredValidator" ClientValidationFunction="airportValidationFunction" ValidateEmptyText="true" ControlToValidate="ResAirport$ResourceValue" ErrorMessage="Choose airport" EnableClientScript="true" Display="None" CssClass="rsValidatorMsg" />


    And the javascript:
    function airportValidationFunction(source, arguments) {
                  alert("airportValidationFunction");
                  arguments.IsValid = true;
                  var flightCheckBox = $find($telerik.$("[id$='ResFlight']").attr("id"));
                  alert("flightCheckBox found");
     
                  if (flightCheckBox.checked == true) {
                      alert("flightCheckBox.check");
                      if (arguments.Value.length == 0) {
                          arguments.IsValid = false;
                      }
                  }
              }

    The alert("flightCheckBox found") is displayed, but not alert("flightCheckBox.check"). I guess there is a syntax error somewhere, but I can't figure out where.


    Regards, Jill-Connie Lorentsen
  4. Plamen
    Admin
    Plamen avatar
    3079 posts

    Posted 30 Apr 2013 Link to this post

    Hello Jill,

     
    Here is the function that worked properly at my side:

    function airportValidationFunction(source, arguments) {
              alert("airportValidationFunction");
              arguments.IsValid = true;
              var flightCheckBox = $telerik.$([id$='ResFlight_AttributeValue']");
             
              if (flightCheckBox.attr("checked") == "checked") {
                  alert("flightCheckBox.check");
                  if (arguments.Value.length == 0) {
                      arguments.IsValid = false;
                  }
              }
          }

    Hope this will solve the issue.
    All the best,
    Plamen
    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.
  5. Jill-Connie Lorentsen
    Jill-Connie Lorentsen avatar
    118 posts
    Member since:
    Nov 2008

    Posted 30 Apr 2013 Link to this post

    Thank you for your reply, but I am not quite there yet...

    The alert("flightCheckBox.check") never shows.
    If I add an alert(flightCheckBox.attr("checked")) the result is Undefined

    Do I put the javascript in the AdvancedForm.ascx or in the default.aspx? I have all the scripts in the default.aspx

    I am sorry, but I am not very familiar with javascript, so I find it very hard to debug.

    Your help is appreciated!


    Regards, Jill-Connie
  6. Plamen
    Admin
    Plamen avatar
    3079 posts

    Posted 30 Apr 2013 Link to this post

    Hi Jill-Connie,

    This code it concerning the advanced form so I will recommend you to put this javascript in the AdvancedForm.js(at the very bottom for example) I am attaching my sample test project that worked properly at my side.

    (flightCheckBox.attr("checked") is supposed to return undefined when the Checkbox is not checked and "checked" otherwise.

    Hope this will be helpful.

    Regards,
    Plamen
    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.
  7. Jill-Connie Lorentsen
    Jill-Connie Lorentsen avatar
    118 posts
    Member since:
    Nov 2008

    Posted 02 May 2013 Link to this post

    Thank you very much for your help!
Back to Top