Code Monkey home page Code Monkey logo

silverware-validator's Issues

Use of Validator on getCMSValidator breaks the Silverstripe Admin

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).

Guzzle update?

Hi,

Is it possible to update Guzzle to version 7.* in the composer file? I get conflicts with other repositories now.

validate depending on choice of other field

Hi,
Is there an option to validate or not validate a field depending on choice of a optionset field? For example: I have an optionset field with different payment options. Depending of the choice of payment I show or hide fields below by jQuery. If fields are hidden they must not validated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.