Re: [CForm] javascript validation doesn't work? [WORKING]
On Aug 4, 2004, at 3:40 PM, Phil Snowdon wrote: I've got the validation working now. Thought I'd share the results and ask a question on style. Both examples work, but as a matter of best practice, which would be preferred? Also which would be more likely to remain in future cocoon releases? I'm not the authority, but I would venture to say that neither one is going to away. The way I think is the older way. I don't care for it, because I like the declarative style of the form definition and I don't like embedding imperative code in it. I think there's a third way... I think you can implement the validation code right in the flowscript, if that suits you. Can't remember the details ATM — check the v2 samples in the forms block I think. ~ml - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [CForm] javascript validation doesn't work? [WORKING]
I've got the validation working now. Thought I'd share the results and ask a question on style. Both examples work, but as a matter of best practice, which would be preferred? Also which would be more likely to remain in future cocoon releases? The validation code has to call existing Java code for specific validation methods. Example 1: Defining the validation in an child of the field element, in form definition xml. If your business or organisation has an *** number, please show it here var validator = new Packages.online.common.model.Validation(); var result = validator.validateNumber(widget.value); if (!result) { widget.setValidationError(new Packages.org.apache.cocoon.forms.validation.ValidationError("Some Error!", false)); } return result; Example 2: By wrapping the existing code as a WidgetValidator and using the flow script to add to the field Element. From form definition xml: If your business or organisation has an *** number, please show it here From flowscript (before showForm()): var validator = new Packages.widgetValidators.NumberValidator(); form.lookupWidget("Number").addValidator(validator); WidgetValidator Class: public class NumberValidator implements WidgetValidator { public boolean validate(Widget w) { boolean result = false; String val = w.getValue().toString(); result = Validation.validateNumber(val); if(!result){ ValidationError err = new ValidationError("Some Error!",false); ((ValidationErrorAware)w).setValidationError(err); } return result; } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [CForm] javascript validation doesn't work?
On Tue, 2004-08-03 at 23:08, Phil Snowdon wrote: > Take this snippet from the samples. Supposedly if the price is > less than one, then it will show a validation error. It > doesn't. > > > > > var success = true; > var price = widget.lookupWidget("dieselprice"); > if (price.value < 1) { > price.setValidationError(new > Packages.org.apache.cocoon.forms.validation.ValidationError("It > can not be that low!", false)); > success = false; > } > > // Must return true/false > return success; > > Where do you place that element, thus as child of what other element? IIRC in the Cocoon 2.1.5 release widget validators belonging to container widgets (such as a repeater or the form itself) are only executed if all children are validated successfully. In current SVN they are however always executed. > > even simpler > > > > return false; > > Note that you shouldn't do this, a validator returning false should always set a validation error somewhere. > > Which should always generate a validation error doesn't seems to > either. > > Is this a known issue? There's a comment in the Form.js code > // FIXME: Remove check for removed syntax later. > if (this.validator != undefined) { > throw "Forms do not support custom javascript validators > anymore. Declare your validators in the form model file."; > } > > Does this mean that we can't use javascript validadtors anymore. > What does it mean by declaring your validators in the form model > file? No no, this has nothing to do with the validators in the form model file. -- Bruno Dumon http://outerthought.org/ Outerthought - Open Source, Java & XML Competence Support Center [EMAIL PROTECTED] [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [CForm] javascript validation doesn't work?
Ok, I found some references in the mailing list to this functionality being removed at 2.1.5 in favour of widget validators. (http://marc.theaimsgroup.com/?l=xml-cocoon-users&m=108639582110249&w=2) So how do they work? Anyone have a sample peice of code? >>> Phil Snowdon 4/08/2004 9:08:51 a.m. >>> Take this snippet from the samples. Supposedly if the price is less than one, then it will show a validation error. It doesn't. var success = true; var price = widget.lookupWidget("dieselprice"); if (price.value < 1) { price.setValidationError(new Packages.org.apache.cocoon.forms.validation.ValidationError("It can not be that low!", false)); success = false; } // Must return true/false return success; even simpler return false; Which should always generate a validation error doesn't seems to either. Is this a known issue? There's a comment in the Form.js code // FIXME: Remove check for removed syntax later. if (this.validator != undefined) { throw "Forms do not support custom javascript validators anymore. Declare your validators in the form model file."; } Does this mean that we can't use javascript validadtors anymore. What does it mean by declaring your validators in the form model file? Cheers Phil - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[CForm] javascript validation doesn't work?
Take this snippet from the samples. Supposedly if the price is less than one, then it will show a validation error. It doesn't. var success = true; var price = widget.lookupWidget("dieselprice"); if (price.value < 1) { price.setValidationError(new Packages.org.apache.cocoon.forms.validation.ValidationError("It can not be that low!", false)); success = false; } // Must return true/false return success; even simpler return false; Which should always generate a validation error doesn't seems to either. Is this a known issue? There's a comment in the Form.js code // FIXME: Remove check for removed syntax later. if (this.validator != undefined) { throw "Forms do not support custom javascript validators anymore. Declare your validators in the form model file."; } Does this mean that we can't use javascript validadtors anymore. What does it mean by declaring your validators in the form model file? Cheers Phil - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]