Commit 670e37e1 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Follow HTML spec for checkbox

Send 'on' value when checked.
Do not add checkbox in the request body if unchecked.
parent 17dbbb40
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var field_json = options.field_json || {}, var field_json = options.field_json || {},
state_dict = { state_dict = {
checked: asBoolean(getFirstNonEmpty(field_json.value, field_json.default)), checked: asBoolean(getFirstNonEmpty(field_json.value,
field_json.default)),
editable: field_json.editable, editable: field_json.editable,
id: field_json.key, id: field_json.key,
name: field_json.key, name: field_json.key,
...@@ -56,19 +57,24 @@ ...@@ -56,19 +57,24 @@
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
var context = this;
if (this.state.editable) { if (this.state.editable) {
return this.getDeclaredGadget('sub') return this.getDeclaredGadget('sub')
.push(function (gadget) { .push(function (gadget) {
return gadget.getContent(); return gadget.getContent();
}) })
.push(function (result) { .push(function (result) {
var final_result = {};
// Automatically add default_%s:int:0 // Automatically add default_%s:int:0
// https://lab.nexedi.com/nexedi/erp5/blob/8ae0706177/product/Formulator/Widget.py#L476 // erp5/blob/8ae0706177/product/Formulator/Widget.py#L476
var key_list = Object.keys(result), i; final_result["default_" + context.state.name + ":int"] = 0;
for (i = 0; i < key_list.length; i += 1) { if (result[context.state.name]) {
result["default_" + key_list[i] + ":int"] = 0; // from MDN checkbox spec:
// checkbox input send 'on' value when checked
// and is not present in the request when unchecked
final_result[context.state.name] = 'on';
} }
return result; return final_result;
}); });
} }
return {}; return {};
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>965.20745.23601.55773</string> </value> <value> <string>968.25417.15017.19182</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1517998687.67</float> <float>1529660724.7</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -47,11 +47,8 @@ ...@@ -47,11 +47,8 @@
</tal:block> </tal:block>
<tr> <tr>
<td>waitForTextPresent</td> <td colspan="3"><b>Verify checked save</b></td>
<td>Save</td>
<td></td>
</tr> </tr>
<tr> <tr>
<td>waitForElementPresent</td> <td>waitForElementPresent</td>
<td>//input[@name="field_my_frozen"]</td> <td>//input[@name="field_my_frozen"]</td>
...@@ -71,6 +68,12 @@ ...@@ -71,6 +68,12 @@
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/save" /> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/save" />
<tr>
<td>assertChecked</td>
<td>//input[@name="field_my_frozen"]</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/go_to_foo_relation_field_view" /> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/go_to_foo_relation_field_view" />
...@@ -86,6 +89,11 @@ ...@@ -86,6 +89,11 @@
<td></td> <td></td>
</tr> </tr>
<tr>
<td colspan="3"><b>Verify unchecked save</b></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/go_to_foo_default_view" />
<tr> <tr>
<td>click</td> <td>click</td>
<td>//input[@name="field_my_frozen"]</td> <td>//input[@name="field_my_frozen"]</td>
...@@ -98,6 +106,29 @@ ...@@ -98,6 +106,29 @@
<td></td> <td></td>
</tr> </tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/save" />
<tr>
<td>assertNotChecked</td>
<td>//input[@name="field_my_frozen"]</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/go_to_foo_relation_field_view" />
<tr>
<td>waitForElementPresent</td>
<td>//input[@name="field_my_frozen"]</td>
<td></td>
</tr>
<tr>
<td>assertNotChecked</td>
<td>//input[@name="field_my_frozen"]</td>
<td></td>
</tr>
</tbody></table> </tbody></table>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -437,6 +437,43 @@ ...@@ -437,6 +437,43 @@
</tr> </tr>
</tal:block> </tal:block>
<tal:block metal:define-macro="go_to_foo_default_view">
<tr>
<td colspan="3"><b>Go to default view</b></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@class, 'ui-header')]//a[@data-i18n='Views']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//div[contains(@class, 'ui-header')]//a[@data-i18n='Views']</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//ul[@class='document-listview']//a[@data-i18n='View']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//ul[@class='document-listview']//a[@data-i18n='View']</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tr>
<td>waitForElementPresent</td>
<td>//input[@name='field_my_id']</td>
<td></td>
</tr>
<tr>
<td colspan="3"><p></p></td>
</tr>
</tal:block>
<tal:block metal:define-macro="go_to_foo_relation_field_view"> <tal:block metal:define-macro="go_to_foo_relation_field_view">
<tr> <tr>
<td colspan="3"><b>Go to relation field view</b></td> <td colspan="3"><b>Go to relation field view</b></td>
......
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