From 046127eeba2e426eb9b0ac0517182d8fea04b628 Mon Sep 17 00:00:00 2001 From: Jonathan Labreuille Date: Wed, 18 May 2016 16:06:31 +0200 Subject: [PATCH] fixed react forms (new bug discovered on new forms with default values not saved) --- assets/css/src/form.styl | 5 +- assets/js/src/form/fields/date.jsx | 32 ++++++++-- assets/js/src/form/fields/select.jsx | 22 ++++++- assets/js/src/form/fields/text.jsx | 8 +-- assets/js/src/form/form.jsx | 17 +++-- assets/js/src/subscribers/form.jsx | 70 +++++++++++++++------ assets/js/src/subscribers/list.jsx | 32 ++++------ lib/Form/Block/Date.php | 11 ++++ lib/Form/Block/Select.php | 7 ++- lib/Models/Subscriber.php | 6 -- lib/Subscription/Pages.php | 4 +- package.json | 1 + views/form/templates/blocks/date_days.hbs | 1 + views/form/templates/blocks/date_months.hbs | 1 + views/form/templates/blocks/date_years.hbs | 1 + views/form/templates/blocks/select.hbs | 2 + views/subscribers/subscribers.html | 10 ++- 17 files changed, 164 insertions(+), 66 deletions(-) diff --git a/assets/css/src/form.styl b/assets/css/src/form.styl index 90dda5fd63..999681a9ad 100644 --- a/assets/css/src/form.styl +++ b/assets/css/src/form.styl @@ -1,2 +1,5 @@ +.mailpoet_form + margin: 0 0 20px 0 + .mailpoet_form td - vertical-align: top !important \ No newline at end of file + vertical-align: top !important diff --git a/assets/js/src/form/fields/date.jsx b/assets/js/src/form/fields/date.jsx index 0b6de1644d..2d7b49deae 100644 --- a/assets/js/src/form/fields/date.jsx +++ b/assets/js/src/form/fields/date.jsx @@ -9,6 +9,13 @@ define([ render() { const yearsRange = 100; const years = []; + + if (this.props.empty_value_label !== undefined) { + years.push(( + + )); + } + const currentYear = Moment().year(); for (let i = currentYear; i >= currentYear - yearsRange; i--) { years.push(( @@ -33,6 +40,13 @@ define([ class FormFieldDateMonth extends React.Component { render() { const months = []; + + if (this.props.empty_value_label !== undefined) { + months.push(( + + )); + } + for (let i = 1; i <= 12; i++) { months.push(( + )); + } + for (let i = 1; i <= 31; i++) { days.push(( + ); + } + + if (this.props.field['filter'] !== undefined) { + filter = this.props.field.filter; + } const options = Object.keys(values).map( (value, index) => { + + if (filter !== false && filter(this.props.item, value) === false) { + return; + } + return (