Jump to:

10994 Posts in 2728 Topics by 1819 members

All other Modules

SilverStripe Forums » All other Modules » NetefxValidator

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3
Go to End
Author Topic: 4477 Views
  • lx
    Avatar
    Community Member
    82 Posts

    Re: NetefxValidator Link to this post

    We made a slight update of the documentation.
    These rules have already been available in 0.4 , but they were not described in the documentation.

    1) If you have textfields where you expect the user to enter a float number (e.g. 0.49) you would expect 0,49 in a german form.
    So for validating values with decimal mark, you can give all numeric rules a second parameter, which specifies the expected decimal mark.

    $rule_BedSize = new NetefxValidatorRule("BedSize", "SMALLEREQUAL", array('2.15',','), "We have no beds longer than 2,15 meters.");

    2) for a CheckboxSetField you can validate min_number_checkboxes_checked and max_number_checkboxes_checked.
    Check the section "FUNCTION rule: using library functions or writing own functions" in the documentation for an example usage.

  • lx
    Avatar
    Community Member
    82 Posts

    Re: NetefxValidator Link to this post

    I just wanted to mention that there is a new version available for download.

    new in 0.45: rule "checkboxes_no_overlapping"

    This rule will just be needed in very rare situations i think.

    example:
    you are managing a class "Party" in modeladmin.
    A Party has the 2 relations to class Member.

    public static $many_many = array('VIP' => 'Member', '' => 'Exclusions' => 'Member');


    So the administrator has to CheckboxSetFields, 1 for choosing the VIPs the other for those member who are definitely not allowed to join the party.

    In this case you can define the validation rule:

    $rule_excludedPersons_notVIP = new NetefxValidatorRule ("Exclusions", NV_FUNCTION, array('NetefxValidatorLibrary',
    'checkboxes_no_overlapping',
    array('field' => 'Exclusions',
    'otherField' => 'VIP')), "you selected people to be VIP and excluded them at the same time.");

    As i said its an edge case.
    But now this is also available.

  • lx
    Avatar
    Community Member
    82 Posts

    Re: NetefxValidator Link to this post

    Thanks to Zauberfisch, there is a completely rewritten version of the module available. (currently version 0.7)
    The module can now be downloaded from github.

    https://github.com/lx-berlin/NetefxValidator

    This version is no more compatible to 0.45 !
    Also the documentation is outdated according to the changes in 0.7
    We will change it as soon as possible.

  • lx
    Avatar
    Community Member
    82 Posts

    Re: NetefxValidator Link to this post

  • Joures
    Avatar
    Community Member
    7 Posts

    Re: NetefxValidator Link to this post

    I'm having som trouble with this module. The validation works fine on the frontend of the app.
    But when i try to access the records from the CMS it breaks with this error:

    [14-Nov-2011 05:31:51] Error at sapphire/core/Object.php line 724: Uncaught Exception: Object->__call(): the method 'removevalidation' does not exist on 'NetefxValidator' (http://example.com/admin/resellers/Installer/10/EditForm/field/Installations/item/125/show)

    Any ideas?

    ------ EDIT -----

    Solved it by simply adding a removeValidation function in NetefxValidator.php

    function removeValidation(){
    $this->rules = null;
    }

  • Joures
    Avatar
    Community Member
    7 Posts

    Re: NetefxValidator Link to this post

    Can you tell me how to get it to work in popups? Been trying for hours. Don't care if the values stays in the fields or not, just want it to work

  • lx
    Avatar
    Community Member
    82 Posts

    Re: NetefxValidator Link to this post

    Hi Jours,

    you said "But when i try to access the records from the CMS it breaks with this error:"

    I think you are managing your data by adding fields to function getCMSFields() of a page.
    Afaik validation is not possible there.

    Normally i manage everything in modeladmin. Modeladmin uses the function getCMSValidator() for validation. So
    you can define all your validation rules in here.

    Try to use the requiredFields validator from Silverstripe. (http://doc.silverstripe.org/sapphire/en/topics/form-validation)
    If this works replace it with the NetefxValidator.

  • Joures
    Avatar
    Community Member
    7 Posts

    Re: NetefxValidator Link to this post

    So if i remove the call to getCMSFields() and add a call to getCMSValidator() with netefx it should work?

    --- EDIT ---

    actually, it worked without adding stuffs. To get the UNIQUE rule to work in the CTF popups i added this to the code:

    ...
    if (isset($this->args[2]) && is_numeric($this->args[2])) {
    $id = $this->args[2];
    } elseif(isset($_REQUEST['ctf']['childID'])){
    $id = $_REQUEST['ctf']['childID'];
    } else {
    $idFieldInForm = (isset($this->args[2]))?$this->args[2]:'ID';
    $id = (isset($data[$idFieldInForm]))?Convert::raw2sql($data[$idFieldInForm]):false;
    }

    if you can put this in a future update it will work in the CTF popups aswell.

    4477 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.