diff --git a/ghost/admin/app/controllers/offer.js b/ghost/admin/app/controllers/offer.js index 5adbe5011a..1383a9e802 100644 --- a/ghost/admin/app/controllers/offer.js +++ b/ghost/admin/app/controllers/offer.js @@ -160,6 +160,7 @@ export default class OffersController extends Controller { } try { + yield this.offer.validate(); yield offer.save(); // replace 'offer.new' route with 'offer' route diff --git a/ghost/admin/app/templates/offer.hbs b/ghost/admin/app/templates/offer.hbs index acb143e7d1..6e6a192935 100644 --- a/ghost/admin/app/templates/offer.hbs +++ b/ghost/admin/app/templates/offer.hbs @@ -24,7 +24,7 @@

Basic

- + - -

Will be shown to members on the Stripe Checkout page

+ + + +

Visible to members on Stripe Checkout page.

@@ -58,7 +60,7 @@
- +
{{#if (eq this.offer.type 'fixed')}} @@ -84,11 +86,13 @@ @class="gh-input" /> {{/if}} -
+ + +
- + {{svg-jar "arrow-down-small"}} - +
@@ -120,10 +124,12 @@ /> {{svg-jar "arrow-down-small"}} - + + + {{#if (eq this.offer.duration "repeating")}} - + - + + + {{/if}}
@@ -141,7 +149,7 @@

Portal settings

- + - + + + - + - + + +
@@ -182,16 +194,19 @@
- + - + + + diff --git a/ghost/admin/app/validators/offer.js b/ghost/admin/app/validators/offer.js index f17400c093..d90261f045 100644 --- a/ghost/admin/app/validators/offer.js +++ b/ghost/admin/app/validators/offer.js @@ -2,7 +2,7 @@ import BaseValidator from './base'; import validator from 'validator'; export default BaseValidator.create({ - properties: ['name'], + properties: ['name', 'amount', 'displayTitle', 'displayDescription', 'code', 'durationInMonths'], name(model) { if (!model.name) { @@ -13,5 +13,40 @@ export default BaseValidator.create({ model.errors.add('name', 'Name cannot be longer than 191 characters.'); this.invalidate(); } + }, + + amount(model) { + if (!model.amount) { + model.errors.add('amount', 'Please enter Amount.'); + this.invalidate(); + } + }, + + displayTitle(model) { + if (!model.displayTitle) { + model.errors.add('displayTitle', 'Please enter Display title.'); + this.invalidate(); + } + }, + + displayDescription(model) { + if (!validator.isLength(model.displayDescription || '', 0, 191)) { + model.errors.add('displayDescription', 'Display description cannot be longer than 191 characters.'); + this.invalidate(); + } + }, + + durationInMonths(model) { + if (model.duration === 'repeating' && !model.durationInMonths) { + model.errors.add('durationInMonths', 'Please enter duration in months.'); + this.invalidate(); + } + }, + + code(model) { + if (!model.code) { + model.errors.add('code', 'Please enter code.'); + this.invalidate(); + } } });