I have a typical ADO.NET EF-driven form that allows the user to input a date. I have put a jQuery datepicker on it but when the user goes to select a date the browser shows some other entries in a dropdown. How do I turn off that dropdown? In traditional ASP.NET I would put autocomplete="off". Not sure of the MVC equivalent.
<div class="editor-field"> <%= Html.TextBoxFor(model => model.date, new { @class = "aDatePicker" })%> <%= Html.ValidationMessageFor(model => model.date) %> </div>
In traditional ASP.NET I would put autocomplete="off".
Click the Display tab. Do one of the following: To enable AutoComplete for the text box, select the Enable AutoComplete check box. To disable AutoComplete for the text box, clear the Enable AutoComplete check box.
Couple of points
If you've more or less already written the site and you don't want to go back and modify all your cshtml to disable autocomplete (we would have had to go back and change hundreds of lines of code throughout the site), you can disable it via Javascript with a ready handler, like so:
//Disable autocomplete throughout the site $(document).ready(function() { $("input:text,form").attr("autocomplete","off"); })
From what I've read you need to disable it at both the form and the textbox level in order for it to work on all versions of Firefox and IE.
Try this:
<%= Html.TextBoxFor( model => model.date, new { @class = "aDatePicker", autocomplete = "off" } )%>
It will generate markup that is close to the following:
<input type="text" id="date" name="date" class="aDatePicker" autocomplete="off" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With