From: Johannes R. <je...@pl...> - 2014-04-24 20:02:21
|
Repository: plone.formwidget.recurrence Branch: refs/heads/master Date: 2014-04-24T22:00:17+02:00 Author: Johannes Raggam (thet) <rag...@ad...> Commit: https://github.com/plone/plone.formwidget.recurrence/commit/ff288b0099d892c977216990f63f8bed993a08d8 plone.app.widgets support: Let the z3c.form widget's get_start_field method prefer 'name' attribute over the 'id' attribute. Looks like, with plone.app.widgets the rendered input field doesn't have an 'id' attribute any more. Also, integrate lates changes from jquery.recurrenceinput.js, which also handles 'name' attributes when trying to get the start field from the surrounding form. Files changed: M CHANGES.rst M plone/formwidget/recurrence/browser/lib/jquery.recurrenceinput.js M plone/formwidget/recurrence/z3cform/widget.py diff --git a/CHANGES.rst b/CHANGES.rst index 9794545..e95abf7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,14 @@ Changelog 1.2.2 (unreleased) ------------------ +- plone.app.widgets support: Let the z3c.form widget's get_start_field method + prefer 'name' attribute over the 'id' attribute. Looks like, with + plone.app.widgets the rendered input field doesn't have an 'id' attribute any + more. Also, integrate lates changes from jquery.recurrenceinput.js, which + also handles 'name' attributes when trying to get the start field from the + surrounding form. + [thet] + - Register plone.app.jquerytools dateinput JavaScript for the 'default' bundle. plone.app.widgets registers it for 'deprecated', but we need it here and it can peacefully coexist with the new pickadate. diff --git a/plone/formwidget/recurrence/browser/lib/jquery.recurrenceinput.js b/plone/formwidget/recurrence/browser/lib/jquery.recurrenceinput.js index ad563eb..5485d79 100644 --- a/plone/formwidget/recurrence/browser/lib/jquery.recurrenceinput.js +++ b/plone/formwidget/recurrence/browser/lib/jquery.recurrenceinput.js @@ -1296,6 +1296,10 @@ // Otherwise, we assume it's an id: realField = $('#' + field); } + if (!realField.length) { + // Still not? Then it's a name. + realField = $("input[name='" + field + "']"); + } return realField; } function findStartDate() { @@ -1305,6 +1309,10 @@ // Find the default byday and bymonthday from the start date, if any: if (conf.startField) { startField = getField(conf.startField); + if (!startField.length) { + // Field not found + return null; + } // Now we have a field, see if it is a dateinput field: startdate = startField.data('dateinput'); if (!startdate) { @@ -1318,6 +1326,11 @@ // Yes it was, get the date: startdate = startdate.getValue(); } + + // convert human readable, non ISO8601 dates, like + // '2014-04-24 19:00', where the 'T' separator is missing. + startdate = startdate.replace(' ', 'T'); + startdate = new Date(startdate); } else if (conf.startFieldYear && conf.startFieldMonth && @@ -1325,6 +1338,12 @@ startFieldYear = getField(conf.startFieldYear); startFieldMonth = getField(conf.startFieldMonth); startFieldDay = getField(conf.startFieldDay); + if (!startFieldYear.length && + !startFieldMonth.length && + !startFieldDay.length) { + // Field not found + return null; + } startdate = new Date(startFieldYear.val(), startFieldMonth.val() - 1, startFieldDay.val()); diff --git a/plone/formwidget/recurrence/z3cform/widget.py b/plone/formwidget/recurrence/z3cform/widget.py index 58a644f..a4f2649 100644 --- a/plone/formwidget/recurrence/z3cform/widget.py +++ b/plone/formwidget/recurrence/z3cform/widget.py @@ -37,6 +37,9 @@ def get_start_field(self): return self.id + '-start' if hasattr(self.form.widgets[self.start_field], 'js_field'): return self.form.widgets[self.start_field].js_field + if hasattr(self.form.widgets[self.start_field], 'name'): + # plone.app.widgets passes name instead of id to input + return self.form.widgets[self.start_field].name return self.form.widgets[self.start_field].id def get_start_date(self): |