Commit 66c065af authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_web_renderjs_ui: check data's validity in floatfield

parent b7f4f3a2
......@@ -148,7 +148,8 @@ def renderField(field, meta_type=None):\n
"title": field.get_value("title"),\n
"required": field.get_value("required"),\n
}\n
\n
if meta_type == "FloatField":\n
result["precision"] = field.get_value("precision")\n
elif meta_type == "DateTimeField":\n
result = {\n
"type": meta_type,\n
......
......@@ -120,7 +120,7 @@
\n
</head>\n
<body>\n
<input type=\'number\' step="0.00000001" />\n
<input type=\'number\' />\n
</body>\n
</html>
......@@ -245,7 +245,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>sven</string> </value>
<value> <string>xiaowu</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -259,7 +259,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>937.51521.250.37802</string> </value>
<value> <string>940.63282.44183.51353</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -277,8 +277,8 @@
</tuple>
<state>
<tuple>
<float>1411576768.35</float>
<string>GMT</string>
<float>1423905795.16</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
......@@ -99,9 +99,9 @@
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string>/*global window, rJS */\n
<value> <string>/*global window, rJS, RSVP, loopEventListener */\n
/*jslint indent: 2, maxerr: 3 */\n
(function (window, rJS) {\n
(function (window, rJS, RSVP, loopEventListener) {\n
"use strict";\n
\n
rJS(window)\n
......@@ -111,13 +111,21 @@
gadget.element = element;\n
});\n
})\n
.declareAcquiredMethod("notifyValid", "notifyValid")\n
.declareAcquiredMethod("notifyInvalid", "notifyInvalid")\n
.declareAcquiredMethod("notifyChange", "notifyChange")\n
.declareMethod(\'render\', function (options) {\n
var input = this.element.querySelector(\'input\'),\n
step = 0.00000001,\n
field_json = options.field_json || {};\n
input.setAttribute(\n
\'value\',\n
field_json.value || field_json.default || ""\n
);\n
if (field_json.precision !== "") {\n
step = 1 / Math.pow(10, field_json.precision);\n
}\n
input.setAttribute("step", step);\n
input.setAttribute(\'name\', field_json.key);\n
input.setAttribute(\'title\', field_json.title);\n
if (field_json.required === 1) {\n
......@@ -136,9 +144,61 @@
result = {};\n
result[input.getAttribute(\'name\')] = input.value;\n
return result;\n
})\n
.declareMethod(\'checkValidity\', function () {\n
var result;\n
result = this.element.querySelector(\'input\').checkValidity();\n
if (result) {\n
return this.notifyValid()\n
.push(function () {\n
return result;\n
});\n
}\n
return result;\n
})\n
\n
.declareService(function () {\n
////////////////////////////////////\n
// Check field validity when the value changes\n
////////////////////////////////////\n
var field_gadget = this;\n
\n
function notifyChange() {\n
return RSVP.all([\n
field_gadget.checkValidity(),\n
field_gadget.notifyChange()\n
]);\n
}\n
\n
// Listen to input change\n
return loopEventListener(\n
field_gadget.element.querySelector(\'input\'),\n
\'change\',\n
false,\n
notifyChange\n
);\n
})\n
\n
.declareService(function () {\n
////////////////////////////////////\n
// Inform when the field input is invalid\n
////////////////////////////////////\n
var field_gadget = this;\n
\n
function notifyInvalid(evt) {\n
return field_gadget.notifyInvalid(evt.target.validationMessage);\n
}\n
\n
// Listen to input change\n
return loopEventListener(\n
field_gadget.element.querySelector(\'input\'),\n
\'invalid\',\n
false,\n
notifyInvalid\n
);\n
});\n
\n
}(window, rJS));</string> </value>
}(window, rJS, RSVP, loopEventListener));</string> </value>
</item>
<item>
<key> <string>title</string> </key>
......@@ -259,7 +319,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>romain</string> </value>
<value> <string>xiaowu</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -273,7 +333,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>937.51520.38687.48861</string> </value>
<value> <string>940.63306.33653.13909</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -291,8 +351,8 @@
</tuple>
<state>
<tuple>
<float>1412082125.19</float>
<string>GMT</string>
<float>1423907635.25</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment