[2012-11-08] Cannot delete page if required CMS field is not filled in #586

Closed
silverstripe-issues opened this Issue Apr 3, 2013 · 11 comments

Projects

None yet

7 participants

@silverstripe-issues

created by: Friksel
created at: 2012-11-08
original ticket: http://open.silverstripe.org/ticket/8009


Cannot delete a page if a required CMS field (with getCMSValidator) is not filled in. It's impossible to delete the page, because the CMS field that's not filled in has changed to read only....

Error message that appears on the topright after clicking 'delete' says 'Validation error'.

Restoring the page doesn't work either and throws the same error message.

Silverstripe 3.0.3-rc1

@silverstripe-issues

comment by: Friksel
created at: 2012-11-08


After removing the function getCMSValidator() from the page I can delete the page without problems, so I would say the solution is to not validate the page during delete!!

@silverstripe-issues

comment by: @chillu (ischommer)
created at: 2012-12-17


See http://open.silverstripe.org/ticket/6032 for a similar issue with ModelAdmin

@simonwelsh simonwelsh added the master label Mar 16, 2014
@svandragt

Duplicate of #736

@robby-nzta

Is there any progress with this?

@kinglozzer
Member

@robby-nzta I think #863 was supposed to resolve this (amongst other issues) but it looks like I may have missed the unpublish action. Is this issue occurring when attempting to unpublish?

@robby-nzta

Thanks, Yes, this is working on Page type.
After reading through my case, the validation is used RequiredFields.
So finally, I should write custom validation for my case.

I have two action doUnpublish and doDelete should bypass validation in my requirement.

http://stackoverflow.com/questions/22492396/silverstripe-conditional-validation

class CustomValidator extends RequiredFields {
public function php($data) {
if($this->form->buttonClicked()->actionName() == 'saveQuote') {
$this->addRequiredField('FieldName'); // ...
} else {
$this->addRequiredField('OtherFieldName'); // ...
}

    return parent::php($data);
}

}

Cheers

@patricknelson
Contributor

If it helps anyone else:

It appears that this is resolved for me by taking into account @kinglozzer's fix above for #863 with one tiny little change: Adding delete action.

My particular situation (which may vary from others): This occurs when, for example, I create a new page type that does have validation of some sort, but immediately decide that I want to delete that accidental creation. Adding the delete action in there solves this for me. Thankfully this is safely and well exposed via the ->setValidationExemptActions() and ->getValidationExemptActions() duo on CMSForm.

@patricknelson
Contributor

By the way, I should share my actual solution (duh): I'm easily able to work around this without modifying any core code via an Extension of CMSForm using the ->updateEditForm() method in my extension. For example:

class CMSMainExtension extends DataExtension {

    /**
     * Update actions to disable validation so that we don't get validation errors when
     * deleting things that have validation since, of course, they don't need it.
     *
     * @param Form $form
     */
    public function updateEditForm(Form $form) {
        if ($form instanceof CMSForm) {
            $actions = array_merge($form->getValidationExemptActions(), array('delete'));
            $form->setValidationExemptActions($actions);
        }
    }

}

Logically you'd need to register the extension as well, like in your config.yml:

CMSMain:
  extensions:
    - CMSMainExtension
@patricknelson patricknelson added a commit to patricknelson/silverstripe-cms that referenced this issue Oct 1, 2015
@patricknelson patricknelson FIX for #586 and possible fix for #736 and relates to #2449: Don't pe…
…rform validation upon deletion, since it necessary.
63e0768
@patricknelson patricknelson added a commit to patricknelson/silverstripe-cms that referenced this issue Oct 1, 2015
@patricknelson patricknelson FIX for #586 and possible fix for #736 and relates to #2449: Don't pe…
…rform validation upon deletion, since it isn't necessary.
61f5e85
@patricknelson
Contributor

Setup PR #1287 to address this directly.

@patricknelson patricknelson added a commit to patricknelson/silverstripe-cms that referenced this issue Oct 9, 2015
@patricknelson patricknelson FIX for #586 and possible fix for #736 and relates to #2449: Don't pe…
…rform validation upon deletion, since it isn't necessary.
db7d0b8
@patricknelson patricknelson added a commit to patricknelson/silverstripe-cms that referenced this issue Oct 9, 2015
@patricknelson patricknelson FIX for #586 and possible fix for #736 and relates to #2449: Don't pe…
…rform validation upon deletion, since it isn't necessary. Cleaned up type hint.
75dc391
@dhensby
Member
dhensby commented Jul 22, 2016

assuming this was fixed in #1297

@dhensby dhensby closed this Jul 22, 2016
@patricknelson
Contributor

Yep, it was.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment