Encountering a conflict between JQuery UI and Bootstrap led me to realize that the textarea or input field was not editable as expected. Despite trying various solutions provided, none successfully addressed the issue of cross-browser support across major browsers. Determined to find a resolution, I developed a solution which I am eager to share and implement on both input text and textarea elements.
(Verified on Desktop: IE (All Versions), Chrome, Safari, Windows Edge, Firefox, Visual Studio Cordova Ripple Viewer on Windows & Visual Studio Cordova Windows 10 Store App)
(Verified on Mobile: Chrome, Firefox, Android Internet Browser & Visual Studio Cordova App on Android & Visual Studio Cordova Windows 8 + 8.1 + 10 Phone App)
The HTML Code:
<textarea contenteditable id="textarea"></textarea>
The CSS Code:
textarea {
-webkit-user-select: text !important;
-khtml-user-select: text !important;
-moz-user-select: text !important;
-ms-user-select: text !important;
user-select: text !important;
/*to ensure background color and text color are distinguishable (as per previous suggestions)*/
background-color:#fff !important;
color:#733E27 !important;
}
The JQuery Code Upon Document Ready
$("textarea").click(function() {
setTimeout(function(){
$("textarea").focus();
//include this if utilizing JQuery UI (Referencing Previous Solutions)
$("textarea").enableSelection();
var val = $("textarea").val();
if (val.charAt(val.length-1) !== " " && val.length !== 1) {
alert(val.length);
val += " ";
}
$("textarea").val(val);
}, 0);
});
if (navigator.userAgent.indexOf('Safari') !== -1 || navigator.userAgent.indexOf('Chrome') !== -1) {
//alert('Its Safari or chrome');
$("textarea").onfocus(function(e) {
setTimeout(function(){
var end;
if ($("textarea").val === "") {
end = 0;
} else {
end = $("textarea").val.length;
}
if ($("textarea").setSelectionRange) {
var range = document.getElementById('textarea').createTextRange();
if (range) {
setTimeout(range, 0, [end, end]);
} else { // IE style
var aRange = document.getElementById('textarea').createTextRange();
aRange.collapse(true);
aRange.moveEnd('character', end);
aRange.moveStart('character', end);
aRange.select();
}
}
e.preventDefault();
return false;
}, 0);
});
}
You can experiment with this solution on my website at www.gahwehsada.com