I have two input fields as shown below in the pic.
I am trying to focus on the next field which is disabled now but after entering maxlength of chars in the first field it would get enabled. And I want the cursor there on the next field automatically after getting enabled.
The code I am using is given below:
.directive('moveNext', function(){
return{
restrict: 'A',
link: function($scope, element){
element.on("input", function(e){
if((element.val().length==element.attr("maxlength"))){
console.log('asdfasdf');
var tabindex = 1;
var $nextelement = $('input[tabindex='+(tabindex+1)+']');
console.log($nextelement);
if($nextelement){
console.log('asdf');
$nextelement.focus();
}
}
});
}
}
});
The first input or textarea in source order that has the autofocus attribute will be focused on page load. In browsers without autofocus support, no fields will be focused on page load, unless otherwise given focus with JavaScript.
A disabled input element is unusable and un-clickable. The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the <input> element usable.
Autofocusing using React useRef() and useEffect() Hooks We can also get the same functionality with the useRef() and useEffect() React Hooks. Here is the same form using these Hooks: import React, { useRef, useEffect } from "react"; const Form = () => { const emailInput = useRef(null); useEffect(() => { if (emailInput.
Try not using ng-disabled instead use disabled property of javascript.
document.getElementById("myText").disabled = true;
And then under your directive make above false first and move the focus on next element like as below:
document.getElementById("myText").disabled = false;
$nextelement.focus();
In your case focus is getting called first after digest cycle before the field gets enabled.
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