Step 3 sender and reply to per newsletter

- added sender_address/sender_name/reply_to_address/reply_to_name
- added validation on all form fields (except checkbox and radio)
This commit is contained in:
Jonathan Labreuille
2015-12-04 12:29:11 +01:00
parent da6e154642
commit 1950d6661f
9 changed files with 45 additions and 26 deletions

View File

@@ -23,7 +23,9 @@ function(
name={ this.props.field.name }
id={ 'field_'+this.props.field.name }
value={ this.props.item[this.props.field.name] }
onChange={ this.props.onValueChange }>
onChange={ this.props.onValueChange }
{...this.props.field.validation}
>
{options}
</select>
);

View File

@@ -123,6 +123,7 @@ function(
placeholder={ this.props.field.placeholder }
multiple={ this.props.field.multiple }
defaultValue={ default_value }
{...this.props.field.validation}
>{ options }</select>
);
}

View File

@@ -6,6 +6,8 @@ function(
) {
var FormFieldText = React.createClass({
render: function() {
var value = this.props.item[this.props.field.name];
if(!value) { value = null; }
return (
<input
type="text"
@@ -17,7 +19,7 @@ function(
}
name={ this.props.field.name }
id={ 'field_'+this.props.field.name }
value={ this.props.item[this.props.field.name] }
value={ value }
placeholder={ this.props.field.placeholder }
defaultValue={ this.props.field.defaultValue }
onChange={ this.props.onValueChange }

View File

@@ -15,7 +15,9 @@ function(
value={ this.props.item[this.props.field.name] }
placeholder={ this.props.field.placeholder }
defaultValue={ this.props.field.defaultValue }
onChange={ this.props.onValueChange } />
onChange={ this.props.onValueChange }
{...this.props.field.validation}
/>
);
}
});

View File

@@ -68,12 +68,25 @@ define(
handleSubmit: function(e) {
e.preventDefault();
// handle validation
if(this.props.isValid !== undefined) {
if(this.props.isValid() === false) {
return;
}
}
this.setState({ loading: true });
// only get values from displayed fields
item = {};
var item = {};
this.props.fields.map(function(field) {
item[field.name] = this.state.item[field.name];
if(field['fields'] !== undefined) {
field.fields.map(function(subfield) {
item[subfield.name] = this.state.item[subfield.name];
}.bind(this));
} else {
item[field.name] = this.state.item[field.name];
}
}.bind(this));
// set id if specified

View File

@@ -45,7 +45,7 @@ define(
tip: "Name & email of yourself or your company.",
fields: [
{
name: 'from_name',
name: 'sender_name',
type: 'text',
placeholder: 'John Doe',
defaultValue: (settings.sender !== undefined) ? settings.sender.name : '',
@@ -54,7 +54,7 @@ define(
}
},
{
name: 'from_email',
name: 'sender_address',
type: 'text',
placeholder: 'john.doe@email.com',
defaultValue: (settings.sender !== undefined) ? settings.sender.address : '',
@@ -75,12 +75,14 @@ define(
{
name: 'reply_to_name',
type: 'text',
placeholder: 'John Doe'
placeholder: 'John Doe',
defaultValue: (settings.reply_to !== undefined) ? settings.reply_to.name : '',
},
{
name: 'reply_to_email',
name: 'reply_to_address',
type: 'text',
placeholder: 'john.doe@email.com'
placeholder: 'john.doe@email.com',
defaultValue: (settings.reply_to !== undefined) ? settings.reply_to.address : ''
},
]
}
@@ -135,6 +137,9 @@ define(
jQuery('#mailpoet_newsletter').parsley();
}
},
isValid: function() {
return (jQuery('#mailpoet_newsletter').parsley().validate());
},
render: function() {
return (
<div>
@@ -147,7 +152,8 @@ define(
endpoint="newsletters"
fields={ fields }
params={ this.props.params }
messages={ messages }>
messages={ messages }
isValid={ this.isValid }>
<p className="submit">
<input