Hi all,
I would need (as I think many of you) a field to enter a value or free text in the UIs of openHAB, so I tried to use a webview to display a small html page containing a text field and some javascript code to manage everything.
This is the html files textInput.html (in OPENHAB_DIR\webapps\static)
<html>
<script language="JavaScript">
function getParam(param)
{
var qs = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=', 2);
if (p.length == 1)
b[p[0]] = "";
else
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'));
return qs[param]
}
function checkInput(id)
{
var x=document.getElementById(id).value;
if (isNaN(x))
{ document.getElementById(id).value = ""
return false;
}
else
{ return true;
}
}
function resetInput(id)
{
document.getElementById(id).value = ""
}
function httpGetAsync(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
function sendValue() {
if checkInput('textInput') {
url = "http://localhost:8080/CMD?" + getParam('item') + "=" + document.getElementById('textInput').value
httpGetAsync(url)
resetInput('textInput')
} else {
resetInput('textInput')
}
}
</script>
<form>
<input name="textInput" id="textInput" type="text" onChange="sendValue()">
</form>
</html>
This is the part of sitemap
Webview url="http://localhost:8080/static/textInput.html?item=ScheduledEvent_hh" height=3
Leaving aside for now the rendering aspects (which can probably be improved), my tests about this technique are the following:
-
It works on Classic UI when visited by a browser on PC
-
It does not work on Classic UI when visited by iPhone (chrome and safari): The input text is not displayed
-
It does not work on Classic UI when visited by Android (chrome): the webview shows connection refused
-
It does not work on HABdroid: clicking on the field the keyboard appears but disappears immediately not allowing text input
-
It works partially on iOS UI app (so it does not work!): all the javascript functions work except function that use XMLHttpRequest () for HTTP GET request
Someone else has tried this technique for entering text?
Thoughts? Suggestions?
(Iām using openHAB 1.x)
Thanks!