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 ...@@ -148,7 +148,8 @@ def renderField(field, meta_type=None):\n
"title": field.get_value("title"),\n "title": field.get_value("title"),\n
"required": field.get_value("required"),\n "required": field.get_value("required"),\n
}\n }\n
\n if meta_type == "FloatField":\n
result["precision"] = field.get_value("precision")\n
elif meta_type == "DateTimeField":\n elif meta_type == "DateTimeField":\n
result = {\n result = {\n
"type": meta_type,\n "type": meta_type,\n
......
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
\n \n
</head>\n </head>\n
<body>\n <body>\n
<input type=\'number\' step="0.00000001" />\n <input type=\'number\' />\n
</body>\n </body>\n
</html> </html>
...@@ -245,7 +245,7 @@ ...@@ -245,7 +245,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>sven</string> </value> <value> <string>xiaowu</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -259,7 +259,7 @@ ...@@ -259,7 +259,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>937.51521.250.37802</string> </value> <value> <string>940.63282.44183.51353</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -277,8 +277,8 @@ ...@@ -277,8 +277,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1411576768.35</float> <float>1423905795.16</float>
<string>GMT</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
...@@ -99,9 +99,9 @@ ...@@ -99,9 +99,9 @@
</item> </item>
<item> <item>
<key> <string>text_content</string> </key> <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 /*jslint indent: 2, maxerr: 3 */\n
(function (window, rJS) {\n (function (window, rJS, RSVP, loopEventListener) {\n
"use strict";\n "use strict";\n
\n \n
rJS(window)\n rJS(window)\n
...@@ -111,13 +111,21 @@ ...@@ -111,13 +111,21 @@
gadget.element = element;\n gadget.element = element;\n
});\n });\n
})\n })\n
.declareAcquiredMethod("notifyValid", "notifyValid")\n
.declareAcquiredMethod("notifyInvalid", "notifyInvalid")\n
.declareAcquiredMethod("notifyChange", "notifyChange")\n
.declareMethod(\'render\', function (options) {\n .declareMethod(\'render\', function (options) {\n
var input = this.element.querySelector(\'input\'),\n var input = this.element.querySelector(\'input\'),\n
step = 0.00000001,\n
field_json = options.field_json || {};\n field_json = options.field_json || {};\n
input.setAttribute(\n input.setAttribute(\n
\'value\',\n \'value\',\n
field_json.value || field_json.default || ""\n field_json.value || field_json.default || ""\n
);\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(\'name\', field_json.key);\n
input.setAttribute(\'title\', field_json.title);\n input.setAttribute(\'title\', field_json.title);\n
if (field_json.required === 1) {\n if (field_json.required === 1) {\n
...@@ -136,9 +144,61 @@ ...@@ -136,9 +144,61 @@
result = {};\n result = {};\n
result[input.getAttribute(\'name\')] = input.value;\n result[input.getAttribute(\'name\')] = input.value;\n
return result;\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
\n \n
}(window, rJS));</string> </value> }(window, rJS, RSVP, loopEventListener));</string> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
...@@ -259,7 +319,7 @@ ...@@ -259,7 +319,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>romain</string> </value> <value> <string>xiaowu</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -273,7 +333,7 @@ ...@@ -273,7 +333,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>937.51520.38687.48861</string> </value> <value> <string>940.63306.33653.13909</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -291,8 +351,8 @@ ...@@ -291,8 +351,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1412082125.19</float> <float>1423907635.25</float>
<string>GMT</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
</object> </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