Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of Validator on getCMSValidator breaks the Silverstripe Admin #1

Open
eehondas opened this issue Sep 10, 2018 · 2 comments
Open

Comments

@eehondas
Copy link

Hi,
first of all thank you for the module. It is very well done so thank you for that.
There is an issue when trying to use the module in the getCMSValidator() function of an object like so

    /**
     * CMS Fields
     * @return Validator
     */
    public function getCMSValidator()
    {
      $validator = Validator::create();
      $validator->setRules(
          'Title',
          [
            RequiredRule::create()
          ]
      );
      return $validator;
    }

And it is that on the first load of a page when the validator is used it breaks the layout of the page because the parsley file does not load correctly, hence stopping a bunch of SS js files from loading.
When trying that approach the admin looks like this:
image
then on reload it's fine.
I do not know if you intended your module to be used in this scenario as you don't officially list it in your documentation, however it can definitely be used in this scenario since it implements the Silverstripe Validator abstract. It works very well after the page reload (all the custom rules work too).
Matter of fact I was using it in the getCMSValidator because I found your module coming from the Shea Dawson ZenValidator one (he lists the use as a CMSValidator).
So long story short, the parsley file is the issue, which would not matter in the way I am using the Validator except that it cannot be de-activated in a straightforward way, I know that you have listed

$validator->setClientSide(false);

as an option, however that does not stop parsley from failing to load on ajax request.
Also trying to override the js_required in the Parsley Backend like so

SilverWare\Validator\Backends\ParsleyBackend:
  js_required:
    - []

does not work because it only adds to the js list.
Luckily you have done well to provide extension hooks so the way I solved this was like such:

class ValidatorFix extends DataExtension
{
  public function updateRequiredJS(&$js){
    $js = array();
  }

}

Which works alright when applied to ParsleyBackend class
.
Sorry for the long description I wanted to make you understand the situation.

Anyway, this is not an issue per se as you already provided devs options to override such behaviour, however I cannot determine why the parsley file conflicts with SS backend so my best suggestion would be the following: if you intend the module to be used as a CMS Validator too I'd suggest that you allow the config file to override the js options completely.
Obviously if you can determine why parsley conflicts it would be even better but I suspect parsley file has a problem in itself (on the ZenValidator page from Shea he has an option to disable the parsley file when the Validator is used in the getCMSValidator function).

@colintucker
Copy link
Member

Hi @eehondas - thanks so much for your detailed issue report. To be honest, I've mainly been using it in the front-end of the site rather than the CMS, however you're correct in stating that if it follows the SilverStripe validation abstracts, theoretically it should also be able to work in the CMS too. When I get a chance, I'm going to have a look at modifying the module so that it will work out-of-the-box in the CMS as well. Thanks again! 👍

@eehondas
Copy link
Author

Hi @colintucker
Not only theoretically, I am actually using your module for a production website with plenty of validation rules on CMS fields and works like a charm. The only requirement is that the fix that I have described needs to be applied. I have also extended the rule-set with a couple of more rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants