diff --git a/baseframe/__init__.py b/baseframe/__init__.py index 2221d7eb..10d7161c 100644 --- a/baseframe/__init__.py +++ b/baseframe/__init__.py @@ -234,6 +234,16 @@ def init_app( filters=['cssrewrite', 'cssmin'], output='css/baseframe-packed.css', ) + js_select2 = Bundle( + assets.require('!jquery.js', 'select2-material.js'), + filters='uglipyjs', + output='js/select2-material-packed.js', + ) + css_select2 = Bundle( + assets.require('select2-material.css'), + filters=['cssrewrite', 'cssmin'], + output='css/select2-material-packed.css', + ) if bundle_js: js_all = Bundle(js_all, bundle_js) if bundle_css: @@ -246,6 +256,8 @@ def init_app( app.assets.register('js_jquery', assets.require('jquery.js')) app.assets.register('js_all', js_all) app.assets.register('css_all', css_all) + app.assets.register('js_select2', js_select2) + app.assets.register('css_select2', css_select2) app.register_blueprint(self, static_subdomain=subdomain) # Optional config for a client app to use a manifest file diff --git a/baseframe/assets.py b/baseframe/assets.py index 4128d632..b206b039 100644 --- a/baseframe/assets.py +++ b/baseframe/assets.py @@ -611,7 +611,7 @@ 'getdevicepixelratio.js', ] } -assets['extra-material.js'][Version('0.0.0')] = { +assets['extra-material.js'][Version('0.1.0')] = { 'requires': [ 'jquery-modal.js', 'jquery.form.js', @@ -619,6 +619,9 @@ 'getdevicepixelratio.js', ] } +assets['extra-material.js'][Version('0.2.0')] = { + 'requires': ['jquery-modal.js', 'jquery.form.js', 'getdevicepixelratio.js'] +} assets['baseframe.js'][Version(__version__)] = { 'requires': [ @@ -665,9 +668,17 @@ assets['baseframe-material.js'][ Version('0.9.21') ] = 'baseframe/js/baseframe-material.js' -assets['baseframe-mui.js'][Version(__version__)] = { +assets['baseframe-mui.js'][Version('0.1.0')] = { + 'requires': [ + 'extra-material.js==0.1.0', + 'mui.js', + 'jquery.tinymce.js>=4.0.0', + 'baseframe-material.js', + ] +} +assets['baseframe-mui.js'][Version('0.2.0')] = { 'requires': [ - 'extra-material.js', + 'extra-material.js==0.2.0', 'mui.js', 'jquery.tinymce.js>=4.0.0', 'baseframe-material.js', @@ -675,6 +686,9 @@ } assets['mui.css'][Version('0.9.21')] = 'baseframe/css/mui.css' -assets['baseframe-mui.css'][Version(__version__)] = { +assets['baseframe-mui.css'][Version('0.1.0')] = { 'requires': ['jquery-modal.css', 'select2-material.css', 'mui.css'] } +assets['baseframe-mui.css'][Version('0.2.0')] = { + 'requires': ['jquery-modal.css', 'mui.css'] +} diff --git a/baseframe/forms/patch_wtforms.py b/baseframe/forms/patch_wtforms.py index a01f41ca..4f3a4b82 100644 --- a/baseframe/forms/patch_wtforms.py +++ b/baseframe/forms/patch_wtforms.py @@ -12,11 +12,15 @@ def _patch_wtforms_add_flags(): + """Patch WTForms validators as required (currently just one type of patch)""" + def add_flags(validator, flags): + """Add more flags to existing WTForms validators""" validator.field_flags = tuple(flags) + tuple( getattr(validator, 'field_flags', ()) ) + # Patch the `EqualTo` validator to add a 'not_solo' flag on any field it is used on add_flags(wtforms.validators.EqualTo, ('not_solo',)) @@ -70,3 +74,36 @@ def field_init( _patch_wtforms_field_init() del _patch_wtforms_field_init + + +def render_script(self, tag=True): + """ + Render the JavaScript necessary (including script tag) for this field. + + This delegates rendering to + :meth:`meta.render_field_script` + whose default behavior is to call the field's widget, passing any + keyword arguments from this call along to the widget. + + :param bool tag: If False, don't include a `` + {%- endassets -%} +{% endblock %} diff --git a/baseframe/templates/baseframe/mui/forms.html.jinja2 b/baseframe/templates/baseframe/mui/forms.html.jinja2 index 4a5a8971..65d5a3a7 100644 --- a/baseframe/templates/baseframe/mui/forms.html.jinja2 +++ b/baseframe/templates/baseframe/mui/forms.html.jinja2 @@ -77,11 +77,21 @@ {%- endif %} - {%- elif field.type in ['SelectField', 'QuerySelectField', 'SelectMultipleField', 'QuerySelectMultipleField', 'UserSelectField', 'UserSelectMultiField', 'AutocompleteField', 'AutocompleteMultipleField', 'GeonameSelectField', 'GeonameSelectMultiField'] and field.widget.html_tag not in ['ul', 'ol'] %} + {%- elif field.type in ['SelectField', 'QuerySelectField', 'QuerySelectMultipleField'] and field.widget.html_tag not in ['ul', 'ol'] %}
{{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}}
+ {%- elif field.type in ['SelectMultipleField'] and field.widget.html_tag not in ['ul', 'ol'] %} +
+ {{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}} + +
+ {%- elif field.type in ['UserSelectField', 'UserSelectMultiField', 'AutocompleteField', 'AutocompleteMultipleField', 'GeonameSelectField', 'GeonameSelectMultiField'] and field.widget.html_tag not in ['ul', 'ol'] %} +
+ {{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}} + +
{%- else %}
{%- if not nolabel %}{%- endif %} @@ -354,6 +364,8 @@ document.getElementById("{{ ref_id }}").submit(); } }) + {%- elif field.type in ['SelectMultipleField'] %} + Baseframe.Forms.enableSelect2(); {%- elif field.type in ['UserSelectField', 'UserSelectMultiField'] %} {%- if config['LASTUSER_CLIENT_ID'] and current_auth.cookie and 'sessionid' in current_auth.cookie %} Baseframe.Forms.lastuserAutocomplete({