First Tab Press Doesn't Work On TextBoxes in MVC 2
I have multiple textboxes that are exhibiting strange behavior in IE 7 and IE 8 (but not IE 9/Chrome):
- When I move focus between the textboxes (without entering any characters), using the tab key, or via mouse click, everything behaves as expected.
- Once I type a character into a textbox, to change focus to the next textbox takes either two presses of the tab key, or two mouse clicks on a different control.
- It appears the first event is being lost somehow?
Here is the code for the controls:
<div class="smpoe-field-container smpoe-div-column-four">
<%=Html.EditorFor(m => m.SegmentNumber, new {model = Model})%>
</div>
<div class="smpoe-field-container smpoe-div-column-four">
<%=Html.EditorFor(m => m.AmountOrPercent, new {model = Model})%>
</div>
<div class="smpoe-field-container smpoe-div-column-four">
<%=Html.EditorFor(m => m.RandomLowNumber, new {model = Model})%>
</div>
They are defined in my ViewModel like this:
[UIHint("InputTextField")]
[DisplayName("Segment Number")]
[DomainModelProperty(Key = "PCS.SegmentNumber")]
public int SegmentNumber { get; set; }
[UIHint("InputTextField")]
[DisplayName("Amount/Percent")]
[DomainModelProperty(Key = "PCPP.AmountOrPercentValue")]
public decimal AmountOrPercent { get; set; }
[UIHint("InputTextField")]
[DisplayName("High Random Number")]
[DomainModelProperty(Key = "PSD.HighRandomNumber")]
public int开发者_运维百科 RandomHighNumber { get; set; }
Addition: I've confirmed I can fix this issue by removing the UIHint pointing to my template. In an effort to figure out what is going on, I've currently stripped my InputTextField down to the following code, and the issue is still occurring:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<div class="smpoe-field-value">
<%=Html.TextBox("", string.Empty)%>
</div>
Does anyone have any clues? Many thanks for any help that can be provided.
Through process of elimination I found this:
$('.smpoe-field-value input,.smpoe-field-value textarea,.smpoe-field-value select').live('change', function() {
var parentForm = $(this).parents("form:first")[0];
if(parentForm == undefined)
parentForm = $(this).parents('.smpoe-entity-identifier')[0];
if(parentForm == undefined)
return false;
jQuery.data(parentForm,"FormUpdated",true);
});
Returning false was resulting in the change being cancelled in IE 7/8 but not in IE 9 or Chrome.
Obviously that routine was initially written/tested on a browser other than IE 7/8 where the intended behavior occurred even with a return of false.
精彩评论