Jump to content
  • 0

Input Rules With Matchs In Universal Module


a.daniello

Question

Hi,

i'm trying to add an "input rule" in "universal module" to check if the field "url" is a specific subdomain.

 

I'm using this code in "input rules":

 

{"url":{
    "valid":{
        "rule": {"matches", "/^[\w.-]+\.midomain\.(com|it)$/"},
        "message":"URL is invalid"
    }
}}

But seems that no rule is applied so i can write anything in my "url" field.

 

Can someone help me, please?

 

Achille

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Not sure why I didn't see this sooner. You probably already discovered the issue, but when specifying parameters (the regex) to a callback ("matches"), an array format is expected. JSON arrays use brackets rather than braces, so the fix would be to simply change the rule from:

"rule": {"matches", "/^[\w.-]+\.midomain\.(com|it)$/"},

to

"rule": ["matches", "/^[\w.-]+\.midomain\.(com|it)$/"],
Link to comment
Share on other sites

  • 0

Finally! :)

 

Thanks Tyson, but nothing: it not works!

 

I wrote rules as in http://docs.blesta.com/display/user/Universal+Module#UniversalModule-InputRules but also with your suggestion no check is processed (i can write everything, without control).

 

Is there a mode to check if order form use this rule?

 

Thanks,

Achille

Link to comment
Share on other sites

  • 0

You could only test adding/editing a service to see if the rules are validating by checking whether an error is generated. Is your Input Rule set for the Package or Service fields?

 

If you create a product with the following service field input rule:

{"hostname":{
    "valid":{
        "rule":"isEmpty",
        "negate":true,
        "message":"Hostname must not be empty"
    }
}}

..and you have a "hostname" service field set, you can check whether the rule validates by adding a service.

Go to add a service from the admin interface, select this product, and don't set a value for the hostname. When you click to Continue, an error should be shown saying "Hostname must not be empty". That will tell you whether the rules are validating. I tested this myself and find it to be working properly.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...