Skip to content
Snippets Groups Projects
Commit 636f13bc authored by Nils G.'s avatar Nils G.
Browse files

Add definition rule for input field maxlength. Enforce on Client and Server side

parent b8962e21
No related branches found
No related tags found
No related merge requests found
......@@ -79,6 +79,15 @@ def submit():
new_input = {"submit": parameters["submit"]}
if JSON_CONTAINS(parameters, [('inputs', dict)]):
#Load role definitions for additional validation (e.g. maxlength)
elements = B64_TO_JSON(room_record.roles)[player_record.role]["elements"]
input_definitions = {}
for element in elements:
if element["type"] == "input":
input_definitions[element["name"]] = element
inputs = parameters["inputs"]
for key in inputs:
......@@ -87,6 +96,9 @@ def submit():
if (not isinstance(inputs[key], str)) or (keytest != key):
return(FAIL(CODE_MISSING))
if input_definitions[key]["length"] and len(inputs[key]) > input_definitions[key]["length"]:
return(FAIL(CODE_MISSING))
inputs[key] = ''.join(c for c in inputs[key] if (c.isalnum() or c == " "))
new_input["inputs"] = inputs
......
......@@ -63,6 +63,7 @@ function renderRole(_definition, _roleIdle) {
var c = element["class"];
var name = element["name"];
var value = element["value"];
var length = element["length"];
if(prompt){
for(var varname in prompt){
......@@ -81,6 +82,9 @@ function renderRole(_definition, _roleIdle) {
case "input":
e = $("<input class='game_input' type='text'/>");
e.attr("placeholder", value);
if(length) {
e.attr("maxlength", length);
}
if(!prompt) {
e.attr("disabled", "true");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment