[CLOSED] Combobox validation

  1. #1

    [CLOSED] Combobox validation

    I have to validate a combobox which contains the following values: ("...", "One", "Two", "Three")
    I need the selected value to be different from "...", but also when it is valid (different from "..."), I have the tip with message "The value in field is invalid."

    Here is my sample code:

    Test.aspx.vb
    Partial Public Class Test : Inherits System.Web.UI.Page
    Private Shared changeLoad As Byte = 0
     Private Sub Test_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       loadFields(pnl1)
     End Sub
     'Loads all fields
     Protected Sub loadFields(ByRef parent As Ext.Net.FormPanel)
      For i = 0 To 10
       If i = 2 + changeLoad Or i = 3 + changeLoad Then
        loadField(parent, i, True, False)
       Else
        loadField(parent, i, False, True)
       End If
      Next
      changeLoad += 1
      If changeLoad >= 7 Then
       changeLoad = 0
      End If
     End Sub
     'Loads each CompositeField.
     Protected Sub loadField(ByRef parent As Ext.Net.FormPanel, _
                 ByRef id As Int32, _
                 ByRef required As Boolean, _
                 ByRef triggerVisible As String)
      Try
       Dim campo As New CompositeField() With {.id = parent.ID & "_" & "cmps_" & id, _
                           .StyleSpec = "background-color:transparent;", _
                           .HideMode = HideMode.Offsets}
       campo.FieldLabel = "Field " & id
       buildField(campo, parent, required, triggerVisible)
      Catch exc As Exception
       Throw
      End Try
     End Sub
     'Builds each CompositeField content.
     Public Sub buildField(ByRef cmps As CompositeField, _
                ByRef parent As FormPanel, _
                ByRef required As Boolean, _
                ByRef triggerVisible As Boolean)
     Try
      Dim txt1 As New ComboBox() With {.Width = 205, _
                       .ID = parent.ID & "_" & cmps.ID & "_txt1", _
                       .HideMode = HideMode.Offsets, _
                       .Editable = False, _
                       .TriggerIcon = TriggerIcon.SimpleArrowDown}
      txt1.Items.Add(New ListItem("...", "0"))
      txt1.Items.Add(New ListItem("One", "1"))
      txt1.Items.Add(New ListItem("Two", "2"))
      txt1.Items.Add(New ListItem("Three", "3"))
      txt1.SelectedItem.Value = "0"
      If required Then
       txt1.Validator = "cboValidator"
       txt1.AddClass("col")
      End If
      parent.Items.Add(cmps)
      cmps.Items.Add(txt1)
    Catch exc As Exception
     Throw
    End Try
     End Sub
    End Class
    Test.aspx
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test.aspx.vb" Inherits="Test" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">  
     <title>test</title> 
       <style type="text/css">         
            .col{background: #FFE9D2 !important;}                  
        </style>
     
      <script type="text/javascript" language="javascript">
       var doSomething = function(txt){alert('clicked: ' + txt);}
       var cboValidator = function(val){if(val=='...'){return false;} else{return true;}};
      </script>  
    </head>
    <body>
      <form id="form1" runat="server">
     
      <ext:ResourceManager ID="extSM" runat="server"></ext:ResourceManager>
     
        <ext:Viewport ID="vp" runat="server">
          <Content>
        <ext:FitLayout ID="ft" runat="server">
         <Items>
        <ext:TabPanel ID="tb" runat="server" LayoutOnTabChange="true">
         <Items>
          <ext:FormPanel ID="pnl1" runat="server" Layout="form" Title="Tab 1" >
           <Content></Content> 
          </ext:FormPanel>            
         </Items>
         <BottomBar>
          <ext:Toolbar ID="Toolbar1" runat="server">
           <Items>
            <ext:Button ID="btnValidate" runat="server" Text="Validate pnl1">
             <Listeners>
              <Click Handler="if(#{pnl1}.getForm().isValid()){alert('pnl1 is valid');}else{alert('pnl1 is invalid');}" />
             </Listeners>
            </ext:Button>
           </Items>
          </ext:Toolbar>
         </BottomBar>
        </ext:TabPanel>   
        </Items>
        </ext:FitLayout>
          </Content>
        </ext:Viewport>
     
      </form>
    </body>
    </html>
    Where I'm worng?
    Thanks.
    Attached Thumbnails Click image for larger version. 

Name:	img1.jpg 
Views:	205 
Size:	12.1 KB 
ID:	2703  
    Last edited by Daniil; May 12, 2011 at 7:52 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Unfortunately, the code you posted is unreadable. Please edit your post. To more info, please see
    Forum Guidelines For Posting New Topics
  3. #3
    It was a problem with cut&paste from visual studio to IE9.
    Now the code is readable.

    Quote Originally Posted by Daniil View Post
    Hi,

    Unfortunately, the code you posted is unreadable. Please edit your post. To more info, please see
    Forum Guidelines For Posting New Topics
  4. #4
    Thanks.

    Validator function message should return true or error message (not false). So, please try:
    var cboValidator = function (val) {
        return val !== '...' ? true : "Invalid";
    };
  5. #5
    This didn't worked, only changed the tip message from (default message) "The value in this field is invalid" to (as you suggested) "Invalid".

    Thanks for the support.

    Quote Originally Posted by Daniil View Post
    Thanks.

    Validator function message should return true or error message (not false). So, please try:
    var cboValidator = function (val) {
        return val !== '...' ? true : "Invalid";
    };
  6. #6
    I have reproduced the issue.

    Here is my test case.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    
        <script type="text/javascript">
            var cboValidator = function (val) {
                return val !== '...' ? true : "Invalid";
            };
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager ID="extSM" runat="server" />
        <ext:CompositeField runat="server">
            <Items>
                <ext:ComboBox runat="server" Validator="cboValidator">
                    <Items>
                        <ext:ListItem Text="..." Value="0" />
                        <ext:ListItem Text="One" Value="1" />
                    </Items>
                    <SelectedItem Value="0" />
                </ext:ComboBox>
            </Items>
        </ext:CompositeField>
        <br />
        <br />
        <br />
        <ext:CompositeField runat="server">
            <Items>
                <ext:ComboBox runat="server" Validator="cboValidator">
                    <Items>
                        <ext:ListItem Text="..." Value="0" />
                        <ext:ListItem Text="One" Value="1" />
                    </Items>
                    <SelectedItem Value="0" />
                </ext:ComboBox>
            </Items>
        </ext:CompositeField>
        </form>
    </body>
    </html>
  7. #7
    Hi,

    Please set CombineErrors="false" for CompositeField
  8. #8
    That worked, you have been very very helpful.

    Mark as CLOSED.

    Thanks.

    Quote Originally Posted by Vladimir View Post
    Hi,

    Please set CombineErrors="false" for CompositeField
  9. #9
    Quote Originally Posted by Vladimir View Post
    Hi,

    Please set CombineErrors="false" for CompositeField
    Thanks!!! Works for me!

Similar Threads

  1. [CLOSED] Combobox - Validation
    By adelaney in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 20, 2012, 1:50 AM
  2. Replies: 1
    Last Post: Feb 16, 2012, 3:27 PM
  3. Replies: 4
    Last Post: Nov 30, 2011, 5:25 AM
  4. Client Side Validation and Validation Status
    By speddi in forum 1.x Help
    Replies: 8
    Last Post: Nov 03, 2011, 11:24 AM
  5. Replies: 3
    Last Post: Jul 11, 2011, 9:43 AM

Tags for this Thread

Posting Permissions