Commit 447e4be3 authored by Georgios Dagkakis's avatar Georgios Dagkakis

Add a new Field (in field definition form) 'autocomplete'

See merge request !1819
parents 8acf9292 2ba349cd
Pipeline #29833 failed with stage
......@@ -452,6 +452,11 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None,
# resolve the base meta_type
meta_type = field.getRecursiveTemplateField().meta_type
try:
autocomplete = field.get_value("autocomplete")
except KeyError:
autocomplete = None
result = {
"type": meta_type,
"title": Base_translateString(field.get_value("title")),
......@@ -460,6 +465,7 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None,
"editable": field.get_value("editable"),
"hidden": field.get_value("hidden"),
"description": field.get_value("description"),
"autocomplete": autocomplete,
}
if preferred_html_style_developer_mode:
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_view</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_view</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>A form with a StringField and a PasswordField with autocomplete attributes</string> </value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>view_autocomplete_field</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>5.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Autocomplete Field</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/Foo_viewAutocompleteField</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>Base_edit</string> </value>
</item>
<item>
<key> <string>action_title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list>
<string>my_string_field_with_autocomplete_attr</string>
<string>my_password_field_with_autocomplete_attr</string>
<string>my_list_field_with_autocomplete_attr</string>
</list>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Foo_viewAutocompleteField</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>Foo_viewFloatField</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_view</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Autocomplete Fields</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -36,6 +36,7 @@ Foo | select_bar
Foo | update_request_content
Foo | view
Foo | view_action_title
Foo | view_autocomplete_field
Foo | view_crash_on_save
Foo | view_developer_mode_action
Foo | view_dialog_with_only_update
......
......@@ -24,6 +24,7 @@
first_item: field_json.first_item,
hidden: field_json.hidden,
error_text: field_json.error_text,
autocomplete: field_json.autocomplete,
// Force calling subfield render
// as user may have modified the input value
render_timestamp: new Date().getTime()
......
......@@ -19,6 +19,7 @@
title: field_json.description,
type: 'password',
hidden: field_json.hidden,
autocomplete: field_json.autocomplete,
// Force calling subfield render
// as user may have modified the input value
render_timestamp: new Date().getTime()
......
......@@ -19,6 +19,7 @@
error_text: field_json.error_text,
title: field_json.description,
hidden: field_json.hidden,
autocomplete: field_json.autocomplete,
trim: true,
maxlength: field_json.maxlength,
// Force calling subfield render
......
......@@ -36,6 +36,7 @@
maxlength: options.maxlength,
min: options.min,
max: options.max,
autocomplete: options.autocomplete,
multiple: options.multiple,
accept: options.accept,
capture: options.capture,
......@@ -112,6 +113,10 @@
textarea.required = false;
}
if (this.state.autocomplete) {
textarea.autocomplete = this.state.autocomplete;
}
if (this.state.editable) {
textarea.readonly = true;
} else {
......
......@@ -25,6 +25,7 @@
error_text: options.error_text || "",
id: options.id,
name: options.name,
autocomplete: options.autocomplete,
title: options.title,
hidden: options.hidden
};
......@@ -66,6 +67,10 @@
select.readonly = false;
}
if (this.state.autocomplete) {
select.autocomplete = this.state.autocomplete;
}
if (modification_dict.hasOwnProperty('value') ||
modification_dict.hasOwnProperty('item_list')) {
fragment = document.createDocumentFragment();
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Zuite" module="Products.Zelenium.zuite"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>renderjs_ui_autocomplete_attribute_suite</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>testAutocompleteOfStringAndPasswordField</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 autocomplete attribute of StringField, PasswordField and ListField</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test autocomplete attribute of StringField, PasswordField and ListField</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/PTZuite_CommonTemplate/macros/init" />
<tr>
<td>store</td>
<td>${base_url}/web_site_module/renderjs_runner</td>
<td>renderjs_url</td>
</tr>
<tr>
<td>open</td>
<td>${renderjs_url}/#/foo_module/1?editable=1</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_app_loaded" />
<tr>
<td>waitForElementPresent</td>
<td>//a[text()="Autocomplete Field"]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//a[text()="Autocomplete Field"]</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//a[text()="Autocomplete Field"]</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//input[@id="field_my_string_field_with_autocomplete_attr" and @autocomplete="family-name"]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//input[@id="field_my_password_field_with_autocomplete_attr" and @autocomplete="new-password"]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//select[@id="field_my_list_field_with_autocomplete_attr" and @autocomplete="tel-country-code"]</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
##############################################################################
#
# Copyright (c) 2011 Nexedi SARL and Contributors. All Rights Reserved.
# Kazuhiko <kazuhiko@nexedi.com>
# Rafael Monnerat <rafael@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import unittest
from Products.ERP5Type.tests.ERP5TypeFunctionalTestCase import ERP5TypeFunctionalTestCase
class TestRenderJSUIAutocompleteAttribute(ERP5TypeFunctionalTestCase):
foreground = 0
run_only = "renderjs_ui_autocomplete_attribute_suite"
def getBusinessTemplateList(self):
return (
'erp5_web_renderjs_ui',
'erp5_web_renderjs_ui_test',
'erp5_ui_test_core',
'erp5_test_result',
)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestRenderJSUIAutocompleteAttribute))
return suite
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testFunctionalRJSAutocompleteAttribute</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testFunctionalRJSAutocompleteAttribute</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal_tests/renderjs_ui_autocomplete_attribute_suite
portal_tests/renderjs_ui_autocomplete_attribute_suite/**
portal_tests/renderjs_ui_check_box_field_zuite
portal_tests/renderjs_ui_check_box_field_zuite/**
portal_tests/renderjs_ui_date_time_field_zuite
......
test.erp5.testFunctionalRJSAutocompleteAttribute
test.erp5.testFunctionalRJSLabelField
test.erp5.testFunctionalRJSIntegerField
test.erp5.testFunctionalRJSCore
......
......@@ -373,7 +373,8 @@ class TextWidget(Widget):
"""Text widget
"""
property_names = Widget.property_names +\
['display_width', 'display_maxwidth', 'input_type', 'extra']
['display_width', 'display_maxwidth', 'input_type', 'extra',
'autocomplete', ]
default = fields.StringField('default',
title='Default',
......@@ -413,6 +414,14 @@ class TextWidget(Widget):
default="text",
required=0)
autocomplete = fields.StringField('autocomplete',
title='Autocomplete',
description=(
"The autocomplete property of the HTML of the field"),
css_class="form-control",
default="",
required=0)
def render(self, field, key, value, REQUEST, render_prefix=None):
"""Render text input field.
"""
......@@ -426,6 +435,7 @@ class TextWidget(Widget):
value=value,
size=field.get_value('display_width'),
maxlength=display_maxwidth,
autocomplete=field.get_value('autocomplete'),
extra=field.get_value('extra'))
else:
return render_element("input",
......@@ -434,6 +444,7 @@ class TextWidget(Widget):
css_class=field.get_value('css_class'),
value=value,
size=field.get_value('display_width'),
autocomplete=field.get_value('autocomplete'),
extra=field.get_value('extra'))
def render_view(self, field, value, REQUEST=None, render_prefix=None):
......@@ -492,6 +503,7 @@ class PasswordWidget(TextWidget):
value=value,
size=field.get_value('display_width'),
maxlength=display_maxwidth,
autocomplete=field.get_value('autocomplete'),
extra=field.get_value('extra'))
else:
return render_element("input",
......@@ -500,6 +512,7 @@ class PasswordWidget(TextWidget):
css_class=field.get_value('css_class'),
value=value,
size=field.get_value('display_width'),
autocomplete=field.get_value('autocomplete'),
extra=field.get_value('extra'))
def render_view(self, field, value, REQUEST=None, render_prefix=None):
......@@ -1182,7 +1195,15 @@ class ListWidget(SingleItemsWidget):
"""List widget.
"""
property_names = Widget.property_names +\
['first_item', 'items', 'size', 'extra', 'extra_item']
['first_item', 'items', 'size', 'extra', 'extra_item', 'autocomplete']
autocomplete = fields.StringField('autocomplete',
title='Autocomplete',
description=(
"The autocomplete property of the HTML of the field"),
css_class="form-control",
default="",
required=0)
size = fields.IntegerField('size',
title='Size',
......@@ -1204,6 +1225,7 @@ class ListWidget(SingleItemsWidget):
css_class=field.get_value('css_class', REQUEST=REQUEST),
size=field.get_value('size', REQUEST=REQUEST),
contents="\n".join(rendered_items),
autocomplete=field.get_value('autocomplete'),
extra=field.get_value('extra', REQUEST=REQUEST))
return "\n".join([list_widget, input_hidden])
......@@ -1783,6 +1805,11 @@ def render_tag(tag, **kw):
else:
extra = ""
# For 'autocomplete' we do not want to add it if there is no value
autocomplete = kw.pop('autocomplete', '')
if autocomplete:
attr_list.append('%s="%s"' % ('autocomplete', html_quote(autocomplete)))
# handle other attributes
for key, value in kw.items():
if value == None:
......
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