Commit ff5355ae authored by Romain Courteaud's avatar Romain Courteaud

GadgetField: use an external field validator.

GadgetField doesn't know how to validate/store REQUEST form data.
Use an external field to handle this task.
The external field must be located in the same form, and can be put in the hidden group if not rendered.

Add a test with a stringfield and a textarea field as validator.
parent 6e53cb2c
......@@ -56,7 +56,7 @@
<!-- Initialize -->
<tr>
<td>waitForElementPresent</td>
<td>//input[@title='field_my_description']</td>
<td>//textarea[@title='field_my_description']</td>
<td></td>
</tr>
......@@ -64,7 +64,7 @@
<tr>
<td>type</td>
<td>//input[@title='field_my_description']</td>
<td>//textarea[@title='field_my_description']</td>
<td>123</td>
</tr>
......@@ -84,14 +84,14 @@
<tr>
<td>waitForElementPresent</td>
<td>//input[@title='field_my_description']</td>
<td>//textarea[@title='field_my_description']</td>
<td></td>
</tr>
<tr>
<td>verifyValue</td>
<td>//input[@title='field_my_description']</td>
<td>//textarea[@title='field_my_description']</td>
<td>123</td>
</tr>
......
<?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>testSaveAndLoadMultiline</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 Gadget Field</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test Gadget Field</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<tr>
<td>open</td>
<td>${base_url}/bar_module/ListBoxZuite_reset</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Reset Successfully.</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${base_url}/bar_module/FooModule_createObjects?num:int=1;portal_type=Bar</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Created Successfully.</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${base_url}/bar_module/Zuite_waitForActivities</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Done.</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${base_url}/bar_module/0/Bar_viewGadgetField</td>
<td></td>
</tr>
<!-- Initialize -->
<tr>
<td>waitForElementPresent</td>
<td>//textarea[@title='field_my_description']</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>//textarea[@title='field_my_description']</td>
<td>123
456</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//button[@title='Save']</td>
<td></td>
</tr>
<tr>
<td>verifyPortalStatusMessage</td>
<td>Data updated.</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//textarea[@title='field_my_description']</td>
<td></td>
</tr>
<tr>
<td>verifyValue</td>
<td>//textarea[@title='field_my_description']</td>
<td>123
456</td>
</tr>
<tr>
<td>open</td>
<td>${base_url}/bar_module/0/Bar_representDescription</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>'123\n456'</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
......@@ -117,7 +117,7 @@
<tr>
<td>waitForElementPresent</td>
<td>//input[@title='field_my_description']</td>
<td>//textarea[@title='field_my_description']</td>
<td></td>
</tr>
......@@ -129,7 +129,7 @@
<tr>
<td>type</td>
<td>//input[@title='field_my_description']</td>
<td>//textarea[@title='field_my_description']</td>
<td>relationFieldTest</td>
</tr>
......@@ -149,7 +149,7 @@
<tr>
<td>waitForElementPresent</td>
<td>//input[@title='field_my_description']</td>
<td>//textarea[@title='field_my_description']</td>
<td></td>
</tr>
......@@ -161,14 +161,14 @@
<tr>
<td>verifyValue</td>
<td>//input[@title='field_my_description']</td>
<td>//textarea[@title='field_my_description']</td>
<td>relationFieldTest</td>
</tr>
<tr>
<td>type</td>
<td>//input[@title='field_my_description']</td>
<td>//textarea[@title='field_my_description']</td>
<td>relationFieldTestSuite</td>
</tr>
......@@ -199,7 +199,7 @@
<tr>
<td>waitForElementPresent</td>
<td>//input[@title='field_my_description']</td>
<td>//textarea[@title='field_my_description']</td>
<td></td>
</tr>
......@@ -211,7 +211,7 @@
<tr>
<td>verifyValue</td>
<td>//input[@title='field_my_description']</td>
<td>//textarea[@title='field_my_description']</td>
<td>relationFieldTestSuite</td>
</tr>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<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_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<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>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Bar_representDescription</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -67,7 +67,10 @@
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
<list>
<string>textarea_validator</string>
<string>stringfield_validator</string>
</list>
</value>
</item>
<item>
......
......@@ -10,8 +10,9 @@
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
<string>gadget_url</string>
<string>title</string>
<string>validator_field_id</string>
</list>
</value>
</item>
......@@ -71,6 +72,10 @@
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
......@@ -86,6 +91,10 @@
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>gadget_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
......@@ -94,6 +103,10 @@
<key> <string>title</string> </key>
<value> <string>Description</string> </value>
</item>
<item>
<key> <string>validator_field_id</string> </key>
<value> <string>textarea_validator</string> </value>
</item>
</dictionary>
</value>
</item>
......@@ -108,7 +121,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: field.restrictedTraverse(\'gadget_stringfield.html\').absolute_url()</string> </value>
<value> <string>python: field.restrictedTraverse(\'gadget_textareafield.html\').absolute_url()</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -188,6 +188,10 @@
<key> <string>title</string> </key>
<value> <string>File</string> </value>
</item>
<item>
<key> <string>validator_field_id</string> </key>
<value> <string>stringfield_validator</string> </value>
</item>
</dictionary>
</value>
</item>
......
......@@ -184,6 +184,18 @@
<key> <string>js_sandbox</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_linelength</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_lines</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>0</int> </value>
......@@ -192,6 +204,18 @@
<key> <string>title</string> </key>
<value> <string>Language</string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>validator_field_id</string> </key>
<value> <string>stringfield_validator</string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <int>0</int> </value>
</item>
</dictionary>
</value>
</item>
......
......@@ -136,6 +136,10 @@
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>data_url</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
......@@ -160,6 +164,10 @@
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
......@@ -180,6 +188,10 @@
<key> <string>title</string> </key>
<value> <string>Right</string> </value>
</item>
<item>
<key> <string>validator_field_id</string> </key>
<value> <string>stringfield_validator</string> </value>
</item>
</dictionary>
</value>
</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>stringfield_validator</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_view_mode_title</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>textarea_validator</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_view_mode_description</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -10,7 +10,5 @@
<script src="gadget_create_manual_dataurl.js" type="text/javascript"></script>
</head>
<body>
<input type='text'/>
</body>
<body><input type='text'/></body>
</html>
\ No newline at end of file
......@@ -4,29 +4,19 @@
"use strict";
rJS(window)
.ready(function (g) {
g.props = {};
})
.ready(function (g) {
return g.getElement()
.push(function (element) {
g.props.element = element;
});
})
.declareMethod('render', function (options) {
var gadget = this;
gadget.props.key = options.key || ""