I'm using Telerik's Kendo UI. On my form, I have 6 textboxes, A, B, C, D, E, and F.
If the value of A is X,Y, or Z, then B-E need to be made read only, and we want to automatically tab over to textbox F.
If the value of A changes, then we need to remove the read only state for B-E, and make it so that tabbing goes in the original order.
I actually have this working for both Firefox and Chrome, but Internet Explorer does not work correctly. Tabbing jumps from these textboxes to a completely separate set of controls unrelated to this.
So how do I maintain 2 possible tab values (-1 or X, where X is the 'default' value a control would be created with) so that I can dynamically tab between controls depending on read only states?
Note that I cannot rely on disabling a control (instead of making it read only) because this causes issues; even if the control has a value, the value does not get transmitted to the server resulting in a null
for that property. (see this SO post)
This is the code:
//This function will toggle the ReadOnly state of a control array
// based on the parent control's value
function SetReadOnly(controlArray, parentComboId)
{
var parentVal = $("#" + parentComboId).val();
var tabIndex = 1;
if (parentComboId == "A")
{
var regex = /07|09|10|88/;
if (regex.test(parentVal) || parentVal == "" || parentVal == "-")
{
isReadOnly = true;
tabIndex = -1;
}
else
{
isReadOnly = false;
tabIndex = 1;
}
for (var i = 0; i < controlArray.length; i++)
{
$("#" + controlArray[i]).prop("readonly", isReadOnly);
SetTabIndexVals2(controlArray[i], 'TEXTBOX', tabIndex);
}
}
else
{
// logic other groups of parent-child controls
}
}
// This function sets the tab index of the control
function SetTabIndexVals(controlID, controltype, tabIndex)
{
try
{
var _eTabIndex;
if (tabIndex == -1)
{
if (controltype == 'TEXTBOX')
{
_eTabIndex = $("#" + controlID).attr('tabindex');
if (_eTabIndex > 0)
{
$("#" + controlID).attr('Oldtabindex', _eTabIndex);
$("#" + controlID).attr('tabindex', tabIndex);
}
}
else
{
// logic for other types of controls
}
}
else
{
if (controltype == 'TEXTBOX')
{
_eTabIndex = $("#" + controlID).attr('Oldtabindex');
if (_eTabIndex == undefined || _eTabIndex < 0 || _eTabIndex == null)
_eTabIndex = $("#" + controlID).attr('tabindex');
$("#" + controlID).attr('Oldtabindex', _eTabIndex);
$("#" + controlID).attr('tabindex', _eTabIndex);
}
else
{
// logic for other types of controls
}
}
} catch (err)
{
logError(err, arguments.callee.trace());
}
}
This function works for drop downs, but not textboxes.