Commit 82c5ecae authored by Tristan Cavelier's avatar Tristan Cavelier

[erp5_web_renderjs_ui] fix changing relation field input state with empty value_text

Update relation field input value only on demand,
changing the state of a relation_input gadget with value_text = ""
now updates the field.

You can reproduce by doing :
- open an object in tab "View" with a relation field (eg my_successor_title) filled
- open a new tab, and edit the field to make it empty
- from the first tab, refresh the view by click on the left panel "View" tab
- the relation field should be emptied.
parent c0aafd6b
"""Create objects with given parameters"""
from DateTime import DateTime
category_list = ('a', 'b', 'a/a1', 'a/a2')
if category_list is None:
category_list = ('a', 'b', 'a/a1', 'a/a2')
big_category_list = ('c1', 'c10', 'c2', 'c20', 'c3', 'c4')
for i in range(start, start + num):
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>start=0, num=10, set_dates=0, portal_type=\'Foo\', create_line=0, big_category_related=False</string> </value>
<value> <string>start=0, num=10, set_dates=0, portal_type=\'Foo\', create_line=0, big_category_related=False, category_list=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -196,6 +196,7 @@
.onStateChange(function (modification_dict) {
var gadget = this,
input = null,
value_text = gadget.state.value_text,
// target_url,
SEARCHING_CLASS_STR = "ui-btn ui-corner-all ui-btn-icon-notext" +
......@@ -224,6 +225,11 @@
buildEditableInputHTML(gadget);
}
input = gadget.element.querySelector("input");
if (modification_dict.hasOwnProperty("value_text")) {
input.value = gadget.state.value_text;
}
gadget.element.querySelector(".search_ul").innerHTML = "";
// Display the airplane link or the search button
if ((gadget.state.value_relative_url) || (gadget.state.value_text)) {
......@@ -236,14 +242,9 @@
return RSVP.Queue()
.push(function () {
var plane = gadget.element.querySelector("a"),
ul = gadget.element.querySelector(".search_ul"),
input = gadget.element.querySelector("input");
ul = gadget.element.querySelector(".search_ul");
plane.href = '';
if (input.value !== gadget.state.value_text) {
input.value = gadget.state.value_text;
}
// uid is known
// User selected a document from a listbox
if ((gadget.state.value_uid) && (!gadget.state.value_text)) {
......
......@@ -311,7 +311,7 @@
</tuple>
<state>
<tuple>
<float>1467993500.68</float>
<float>1541669313.00</float>
<string>UTC</string>
</tuple>
</state>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testRelationFieldRefresh</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test RenderJS UI</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test RenderJS UI</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<!-- Clean Up -->
<tr>
<td>open</td>
<td>&#36;{base_url}/foo_module/ListBoxZuite_reset</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Reset Successfully.</td>
<td></td>
</tr>
<!-- Initialize -->
<tr>
<td>open</td>
<td>&#36;{base_url}/foo_module/FooModule_createObjects?num:int=2&amp;category_list:list=a&amp;category_list:list=</td>
<td></td>
</tr>
<tr>
<td>waitForTextPresent</td>
<td>Created Successfully.</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/wait_for_activities" />
<tr>
<td>open</td>
<td>&#36;{base_url}/web_site_module/renderjs_runner/#/foo_module?editable=true</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_app_loaded" />
<!-- Go to foo_module/0 in View tab -->
<tr>
<td>waitForElementPresent</td>
<td>//a[text()="Title 0"]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//a[text()="Title 0"]</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<!-- Check the relation field is up to date -->
<tr>
<td>verifyValue</td>
<td>//input[@name="field_my_foo_category_title"]</td>
<td>a</td>
</tr>
<!-- Place a mark on the element to check later if it is correctly updated (not re-created) -->
<tr>
<td>storeEval</td>
<td>document.getElementById("selenium_myiframe").contentWindow.document.querySelector('input[name="field_my_foo_category_title"]').setAttribute("test-relation-field-refresh", "1")</td>
<td>dummy</td>
</tr>
<!-- Trigger update the relation field with an empty value -->
<tr>
<td>click</td>
<td>//a[@data-i18n="Next"]</td>
<td></td>
</tr>
<!-- When pressing Next button, the spinner spins twice. So we can't use the macro `wait_for_content_loaded`
because selenium sometimes misses one spinner (bad timing). By checking the header title we ensure the
spins are done. -->
<tr>
<td>waitForTextPresent</td>
<td>Foo: Title 1</td>
<td></td>
</tr>
<!-- Check the element is updated, not re-created -->
<tr>
<td>verifyElementPresent</td>
<td>//input[@name="field_my_foo_category_title" and @test-relation-field-refresh="1"]</td>
<td></td>
</tr>
<!-- The field should be updated to empty -->
<!-- Here waitForTextNotPresent or waitForElementPresent passes no matter the state of the field, because the field is updated in javascript (not in html attributes) and so the selection //input[@value=''] does not work. -->
<!-- When not passing, you can see that the plane is correctly replaced by a magnifying glass, as if the field was only partly updated -->
<tr>
<td>verifyValue</td>
<td>//input[@name="field_my_foo_category_title"]</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
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