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 @@
.declareMethod('render', function (options) {
var field_json = options.field_json || {},
state_dict = {
checked: asBoolean(getFirstNonEmpty(field_json.value, field_json.default)),
checked: asBoolean(getFirstNonEmpty(field_json.value,
field_json.default)),
editable: field_json.editable,
id: field_json.key,
name: field_json.key,
......@@ -56,19 +57,24 @@
})
.declareMethod('getContent', function () {
var context = this;
if (this.state.editable) {
return this.getDeclaredGadget('sub')
.push(function (gadget) {
return gadget.getContent();
})
.push(function (result) {
var final_result = {};
// Automatically add default_%s:int:0
// https://lab.nexedi.com/nexedi/erp5/blob/8ae0706177/product/Formulator/Widget.py#L476
var key_list = Object.keys(result), i;
for (i = 0; i < key_list.length; i += 1) {
result["default_" + key_list[i] + ":int"] = 0;
// erp5/blob/8ae0706177/product/Formulator/Widget.py#L476
final_result["default_" + context.state.name + ":int"] = 0;
if (result[context.state.name]) {
// 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 {};
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>965.20745.23601.55773</string> </value>
<value> <string>968.25417.15017.19182</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1517998687.67</float>
<float>1529660724.7</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -47,11 +47,8 @@
</tal:block>
<tr>
<td>waitForTextPresent</td>
<td>Save</td>
<td></td>
<td colspan="3"><b>Verify checked save</b></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//input[@name="field_my_frozen"]</td>
......@@ -71,6 +68,12 @@
<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" />
......@@ -86,6 +89,11 @@
<td></td>
</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>
<td>click</td>
<td>//input[@name="field_my_frozen"]</td>
......@@ -98,6 +106,29 @@
<td></td>
</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>
</body>
</html>
\ No newline at end of file
......@@ -437,6 +437,43 @@
</tr>
</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">
<tr>
<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