vivin / regula

Regula: An annotation-based form-validation framework in Javascript
126 stars 24 forks source link

regula.ovveride does not work #74

Closed mfatihercik closed 9 years ago

mfatihercik commented 9 years ago

I could not run below code given in example. it always throw exception and exception message is "regula.override expects a valid constraintType attribute in the options argument"

regula.override({ name: "PasswordsMatch", defaultMessage: "Your passwords do not match." });

vivin commented 9 years ago

Hmm, that should not be happening. Do you have a fiddle or something that displays the issue?

mfatihercik commented 9 years ago

Here is fiddle and its screanshoot Thanks for this great library. image

https://jsfiddle.net/kwzpykts/

vivin commented 9 years ago

Thanks! So it looks like the documentation is out-dated. I'm guessing that at some point in time I had regula.override accept a name parameter. However, currently it accepts a constraintType parameter. This is why you're seeing an error. I need to update the documentation but I haven't gotten around to it due to being extremely busy with work and school! The correct invocation for regula.override would be:

regula.override({
    name: regula.Constraint.PasswordsMatch,
    defaultMessage: "Your passwords do not match."
});
mfatihercik commented 9 years ago

İt didn't work. there are two override(options) method in "dist/regula-1.3.4.js" file. This is main problem Second one override the first one. Second "override" method explicity chek "constraintType"

some code from Second "override(options)" method: /* * Function that lets you override a previously-defined constraint. Delegates to ConstraintService. * @param options / function override(options) { if (!options) { throw new ExceptionService.Exception.IllegalArgumentException("regula.override expects options"); }

    if (typeof options.constraintType == "undefined") {
        throw new ExceptionService.Exception.IllegalArgumentException("regula.override expects a valid constraintType attribute in the options argument");
    }

some code First "override(options)" method: /* * Overrides the definition of a constraint. If the constraint is a compound constraint, then this function also * checks to make sure that there are no cycles in the composition graph. * @param options / function override(options) { var async = typeof options.async === "undefined" ? constraintDefinitions[options.name].async : options.async; var validator = options.validator; if(options.validatorRedefined && !options.formSpecific) { validator = ValidationService.wrapValidatorWithEmptyCheck(validator); }

vivin commented 9 years ago

Let me look into this in some more detail. I must have messed something up when I refactored last time. Using constraintType should work since that's what the tests do. On Mar 16, 2015 12:19 AM, "mfatihercik" notifications@github.com wrote:

İt didn't work. there are two override(options) method in "dist/regula-1.3.4.js" file. This is main problem Second one override the first one. Second override method explicity chek "constraintType"

some code from Second override(options) method: /**

  • Function that lets you override a previously-defined constraint. Delegates to ConstraintService.
  • @param https://github.com/param options */ function override(options) { if (!options) { throw new ExceptionService.Exception.IllegalArgumentException("regula.override expects options"); }

    if (typeof options.constraintType == "undefined") { throw new ExceptionService.Exception.IllegalArgumentException("regula.override expects a valid constraintType attribute in the options argument"); }

some code First function override(options) method: /**

  • Overrides the definition of a constraint. If the constraint is a compound constraint, then this function also
  • checks to make sure that there are no cycles in the composition graph.
  • @param https://github.com/param options */ function override(options) { var async = typeof options.async === "undefined" ? constraintDefinitions[ options.name].async : options.async; var validator = options.validator; if(options.validatorRedefined && !options.formSpecific) { validator = ValidationService.wrapValidatorWithEmptyCheck(validator); }

— Reply to this email directly or view it on GitHub https://github.com/vivin/regula/issues/74#issuecomment-81463656.

sayling commented 9 years ago

Just wanted to add that I've been experiencing this too - (much head scratching when my exact copy of the example didn't work!)

I've also tried explicitly referring to the constraint (regula.constraint) as you've mentioned with no success, so definitely something awry.

Will keep an eye out for a resolution - thanks for the library by the way!

vivin commented 9 years ago

Thanks! I'll probably have a fix for this out this weekend. Sorry for the trouble!

On Wed, Mar 18, 2015 at 6:15 PM, sammyjopeters notifications@github.com wrote:

Just wanted to add that I've been experiencing this too - (much head scratching when my exact copy of the example didn't work!)

I've also tried explicitly referring to the constraint (regula.constraint) as you've mentioned with no success, so definitely something awry.

Will keep an eye out for a resolution - thanks for the library by the way!

— Reply to this email directly or view it on GitHub https://github.com/vivin/regula/issues/74#issuecomment-83246572.

Ruin untold; And thine own sadness, Sing in the grass, When eve has forgot, that no more hear common things that gleam and pass; But seek alone to lip, sad Rose of love and ruin untold; And thine own mother Can know it as I know More than another What makes your own sadness, Set in her eyes.

$s="01:11:02:11:01:11:02:13:01:11:01:11:01:13:02:12:01:13:01:11: 04:11:06:12:04:11:01:12:01:13:02:12:01:14:01:13:01:11:03:12: 01:11:04:12:02:11:01:11:01:13:02:11:03:11:06:11:01:11:05:12: 02:11:01:11:01:13:02:11:02:12:01:12:04:11:06:12:01:11:04:12: 04:11:01:12:03:12:01:12:01:11:01:12:01:12:02:11:01:11:01:13: 02:11:01:02:11:01:12:02"; @a=split(/:/,$s);$j="";foreach$c(@a) {@n=split(//,$c);$j.=$n[0]x$n[1];} for($i=0;$i<$j=~y///c;$i+=8){print chr(unpack("N",pack("B32",substr("0"x32 .substr($j,$i,8),-32))));}

vivin commented 9 years ago

BTW, the code I wrote for the workaround has a bug; name should be constraintType:

regula.override({
    constraintType: regula.Constraint.PasswordsMatch,
    defaultMessage: "Your passwords do not match."
});
vivin commented 9 years ago

Sorry for my late response! I was really busy with school and work. So it looks like the issue is with the documentation. At some point I change override to use constraintType. @mfatihercik the two regula.override functions that you are seeing don't conflict. One is defined in regula.js, whereas the other comes from a different module. The workaround I posted above this comment should work correctly. Let me know if you have anymore questions!

vivin commented 9 years ago

Documentation fixed.