1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-24 17:30:55 +00:00

Allow Max control to add maxlength to text input. Update docs.

This commit is contained in:
Ian Gray 2022-01-14 20:24:23 +00:00
parent 254912aee5
commit 6a513e9f65
4 changed files with 21 additions and 4 deletions

View File

@ -267,6 +267,17 @@ The textinput works very similar like the number input but with a string. You
can enter a String into it and when you are done with your change it is sent to
the ESP.
If you attach a Max control to the text input then a max length will be applied
to the control.
```
text = ESPUI.text("Label", callback, ControlColor::Dark, "Initial value");
ESPUI.addControl(ControlType::Max, "", "32", ControlColor::None, text);
```
However even with a set maximum length, user input should still be validated
because it is easy to bypass client-side checks.
#### Graph
![graph](https://github.com/s00500/ESPUI/blob/master/docs/ui_graph.png)

6
data/js/controls.js vendored
View File

@ -441,9 +441,15 @@ function start() {
if (data.parentControl) {
var parent = $("#id" + data.parentControl + " input");
if (parent.size()) {
if(!parent.attr("type")) {
//type is not set so therefore it is a text input
parent.attr("maxlength", data.value);
} else {
//type might be range (slider) or number
parent.attr("max", data.value);
}
}
}
break;
case UI_STEP:

View File

@ -26,7 +26,7 @@ data.selected+
data.label+
"</option>");}
break;case UI_MIN:if(data.parentControl){var parent=$("#id"+data.parentControl+" input");if(parent.size()){parent.attr("min",data.value);}}
break;case UI_MAX:if(data.parentControl){var parent=$("#id"+data.parentControl+" input");if(parent.size()){parent.attr("max",data.value);}}
break;case UI_MAX:if(data.parentControl){var parent=$("#id"+data.parentControl+" input");if(parent.size()){if(!parent.attr("type")){parent.attr("maxlength",data.value);}else{parent.attr("max",data.value);}}}
break;case UI_STEP:if(data.parentControl){var parent=$("#id"+data.parentControl+" input");if(parent.size()){parent.attr("step",data.value);}}
break;case UI_GRAPH:if(data.visible){addToHTML(data);graphData[data.id]=restoreGraphData(data.id);renderGraphSvg(graphData[data.id],"graph"+data.id);}
break;case ADD_GRAPH_POINT:var ts=Math.round(new Date().getTime()/1000);graphData[data.id].push({x:ts,y:data.value});saveGraphData();renderGraphSvg(graphData[data.id],"graph"+data.id);break;case CLEAR_GRAPH:graphData[data.id]=[];saveGraphData();renderGraphSvg(graphData[data.id],"graph"+data.id);break;case UI_ACCEL:if(hasAccel)break;hasAccel=true;if(data.visible){addToHTML(data);requestOrientationPermission();}

File diff suppressed because one or more lines are too long