mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Added error handling for product details page
refs https://github.com/TryGhost/Team/issues/678 Product name is a mandatory field for a custom product, this change adds error handling on save and custom error message if product is attempted to save without name.
This commit is contained in:
parent
76319c2717
commit
42463e4fdd
3 changed files with 10 additions and 2 deletions
|
@ -160,6 +160,10 @@ export default class ProductController extends Controller {
|
|||
@task({restartable: true})
|
||||
*saveTask() {
|
||||
this.send('validatePaidSignupRedirect');
|
||||
this.product.validate();
|
||||
if (this.product.get('errors').length !== 0) {
|
||||
return;
|
||||
}
|
||||
if (this.settings.get('errors').length !== 0) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -29,10 +29,10 @@
|
|||
<h4 class="gh-main-section-header small bn">Product details</h4>
|
||||
<div class="gh-main-section-content grey gh-product-details-form">
|
||||
<div class="gh-product-details-fields">
|
||||
<GhFormGroup @property="name" @classNames="max-width">
|
||||
<GhFormGroup @errors={{this.product.errors}} @hasValidated={{this.product.hasValidated}} @property="name" @classNames="max-width">
|
||||
<label for="product-name">Product name</label>
|
||||
<GhTextInput data-test-input="product-name" @id="product-name" @value={{product.name}}/>
|
||||
<GhErrorMessage @property="name" />
|
||||
<GhErrorMessage @errors={{this.product.errors}} @property="name" />
|
||||
</GhFormGroup>
|
||||
|
||||
<GhFormGroup @property="description" @classNames="max-width">
|
||||
|
|
|
@ -5,6 +5,10 @@ export default BaseValidator.create({
|
|||
properties: ['name'],
|
||||
|
||||
name(model) {
|
||||
if (!model.name) {
|
||||
model.errors.add('name', 'Please enter Name.');
|
||||
this.invalidate();
|
||||
}
|
||||
if (!validator.isLength(model.name || '', 0, 191)) {
|
||||
model.errors.add('name', 'Name cannot be longer than 191 characters.');
|
||||
this.invalidate();
|
||||
|
|
Loading…
Add table
Reference in a new issue