Json validation files

I'm looking for the 'best practice' in handling the validation section on dynamic forms. When I load a new form I am overwriting the elements of the form. Some of the forms have unique validation functions. I see how to do this by passing the object on the generic save and checking if input elements exist and if so perform the validation. This means that for example I need to check if there is a password file on each form (when in reality it is on one form) . Is there a way of loading the validation section from an external json file? I am happy that the main functions are loaded at initiation but would like the calls to come from the loaded validation file. If this is possible, is it possible to load the elements and validation sections in one ajax call (I could also use this for contextual menus as well) Many thanks Clive

Comments

  • edited February 7

    When you add an input to a form, the common approach is to include the validation rule in input's config.form.validate() will consider this rule as well:

    form.addView({ 
        view:"text", name:"new",
        validate:webix.rules.isNotEmpty
    });

    > Is there a way of loading the validation section from an external json file?

    It's possible to modify therules object:

    form.addView({ view:"text", name:"new" });
    form.config.rules.new = webix.rules.isNotEmpty;

    However, please nothe that the JSON format does not support functoins.

    To check if the particular control is in the form, you can also write a complex rule:

    rules:{
        "new":function(value, valuesObj, name){
            if (this.elements[name])
                return value?true:false;
            return true
        }
    }
  • Thanks for the info. This goes someway to solving the problem. If I want to use one of the built in webix.rules everything is OK. Is it possible to add a new entry into webix.rules to create a new generic validation function, without really breaking into the webix code?
    eg. to validate if a password is strong enough, but must be generic rather than attached to one named control.

  • Hi

    I have answered my own question by adding code into my framework. I have tested it with true and false returns OK, just need to add the real test routine. Please let me know if this will cause any problems within the standard code. webix.rules.my_test=function(t){ webix.alert("my_test"); return true; };

    many thanks as always

  • edited February 16

    We strongly not recommend editing the source code, as it may cause conflicts with the future updates.

    Instead, you canextend therules object in your app:

    webix.extend(webix.rules, { isTested:function(value){ return true } });
  • Thanks, exactly what I was looking for. I agree it's best not to touch source code.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

In this Discussion