locked
jQuery Validate - unexpected results RRS feed

  • Question

  • User379720387 posted

    I have used jquery validation in other code and I have always been able (with your help) to get it working.

    With is different this time is that the validation needs to work inside a dialog, similar to the example at mikesdotnetting something jquery forms.

    I have:

    an input text box for city where the validation works

    a dropdown with states where the validation works

    an input text box for zip code where the validation works

    two radio buttons for monthly billing Yes or No, where the validation does not work.

    The name for the radio buttons is "account"

    When entries do not meet the validation rules I get a message displayed by tips = $( ".validateTips" ); at the top of the dialog box.

    With the validation rule for the radio button as is I get --
    [14:10:05.032] TypeError: o.val(...) is undefined @ http://localhost:49679/Members/ShowBarns:415

    but no message.

    I am thinking the value of account should be either true or false.

    Where am I going wrong with this?

    TIA

    Robert

                <label for="city">City</label>
                <input type="text" name="city" id="city" class="text ui-widget-content ui-corner-all" />   
                
                <div id="statezip1">
                State: @if (!ModelState.IsValidField("state")) {<text>class="error-label"</text>}
                <select data-val="true" data-val-required="State is required." name="state" id="state" class="text ui-widget-content ui-corner-all jqformstate" data-validation-engine="validate[required]" >
                <option value="">Select</option>
                    @foreach (var st in barnstates)
                    { 
                    <option value="@st.StateId">@st.StateId</option>
                    }   
                </select><span data-valmsg-for="state" data-valmsg-replace="true"></span></div>
                <div id="statezip2">
                <label for="zip">Zip</label>
                <input type="text" name="zip" id="zip" maxlength="5" class="text ui-widget-content ui-corner-all jqformzip" /></div><br/>
                
                <div id="billing">
                <label for="account" @if (!ModelState.IsValidField("account")) {<text>class="error-label"</text>}> Monthly Billing: @Html.ValidationMessage("account") </label>
                <input type="radio" name="account" value="True" data-validation-engine="validate[required]" />Yes
                <input type="radio" name="account" value="False"/>No<br/> 
                </div>

    Here are some of the functional elements for the validation:

        city        = $("#city"),
        state       = $("#state"),
        zip         = $("#zip"),
        account     = $("#account"),
        allFields = $([]).add(city).add(state).add(zip).add(account),
        tips = $( ".validateTips" );

    AND

    var bValid = true;
                    allFields.removeClass("ui-state-error");
                    bValid = bValid && checkLength(city, "City", 5, 40);
                    bValid = bValid && checkLength(state, "State", 2, 2);
                    bValid = bValid && checkLength(zip, "Zip", 5, 5);

    Wednesday, July 17, 2013 2:13 PM

All replies