1

I am using Yii2 ActiveForm to make a default templated registration form. In the form the user must specify a signup key in order to complete the registration. The signup key must have a length between 6 and 10 characters.

I have deleted all other validation rules for my form except the one I am having trouble with. The rule is being applied, but is rendering a default form validation message.

Here is the rule in question:

[ 
    'betaKey',
    'string',
    'length' => [6, 10],
    'message' => 'Signup Codes are between 6 and 10 characters.' 
]

The above rule is being applied, I know this because when I change the length to [2, 10] the rule is no longer triggered. I have read the documentation, though please feel free to let me know if I have missed something.

Here is the javascript being rendered by Yii:

yii.validation.string(value, messages, {
    "message": "Signup Codes are between 6 and 10 characters.",
    "min": 2,
    "tooShort": "Beta Key should contain at least 2 characters.",
    "max": 10,
    "tooLong": "Beta Key should contain at most 10 characters.",
    "skipOnEmpty": 1
});

message is never rendered by the validator. All other core-validators in Yii2 use message for specifying a custom error message. Why is that not the case here?

BajaBob
  • 2,643
  • 3
  • 24
  • 26

1 Answers1

2

The documentation does not say anything about the two characteristics, "tooShort" and "tooLong". I was able to set these explicitly and the form works as intended now. I wonder if this is expected functionality by the developers as "message" is still a valid input. At any rate I hope this helps anyone else having similar issues.

        [ 
            'betaKey',
            'string',
            'length' => [2, 10],
            'tooShort' => "Test-Short",
            'tooLong' => "Test-Long"
        ]
BajaBob
  • 2,643
  • 3
  • 24
  • 26
  • Remember downvotes on answers cost reputation. If you are going to use it, you should have a good reason. – gunr2171 Feb 26 '15 at 16:52
  • not sure why this was downvoted. I upvoted it to counteract. It is a valid answer and more to the points something that works but it is not documented. – Mihai P. Feb 27 '15 at 04:52