shivani
shivani

Reputation: 1028

On validation prevent calender control to open

I want to prevent open calendar control on save button at time of validation fire , I am not able to find how can I prevent It

I have one calendar control in form , select date validation fire on save button after validation it will direct focus on calendar control and open calendar automatically , business don't want to open calendar control

HTML

<div class="col-lg-3 col-md-4 col-sm-6">
           <div class="form-group datepicker">
                   <label>Project Start Date </label>
                       <asp:TextBox ID="ProjectStartDate" TabIndex="27" ClientIDMode="Static" runat="server" CssClass="form-control"></asp:TextBox>
                        <asp:HiddenField ID="hdnProjectStartDate" runat="server" Value="" />
            </div>
 </div>


enter image description here

I want to prevent open calendar open on save button
let me know if any solution over there

Thank you

Upvotes: 1

Views: 201

Answers (2)

shivani
shivani

Reputation: 1028

I have solve this issue to change in formValidation.JS
In this file there is one function

      // Determined the first invalid field which will be focused on automatically
        var ns = this._namespace;
        for (var i = 0; i < this.$invalidFields.length; i++) {
            var $field    = this.$invalidFields.eq(i),
                autoFocus = this.isOptionEnabled($field.attr('data-' + ns + '-field'), 'autoFocus');
            if (autoFocus) {
                // Focus the field 
                //$field.focus();                    
                return false;
                break;
            }
        }

On validation it will auto focus that element & after focus calendar control will open automatically because of focus

Comment this line for prevent focus on calendar control

 $field.focus();    

Thank you !!

Upvotes: 1

Eyup Yusein
Eyup Yusein

Reputation: 411

What calendar or date picker control are you using? jQuery UI, Telerik AJAX, Control Toolkit AJAX, Kendo?

For a general ASP.NET validation scenario, the textbox won't be focused automatically. You will need to set the following property to True explicitly do to that:

SetFocusOnError="true"

                <asp:TextBox runat="server" ID="ProjectStartDate"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="* Required"
                    ForeColor="Red" ControlToValidate="ProjectStartDate" SetFocusOnError="false">
                </asp:RequiredFieldValidator>
                <asp:Button ID="Button1" runat="server" Text="Submit" />

You can check your code-behind whether you have defined this property somewhere.

Upvotes: 0

Related Questions