![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
The CFFORM documentation mentions an "errors" object that can be accessed via
actionscript in Flash format. I can't get the sample code in the docs to work. Has anyone successfully accessed this object? Can you give me some more detail regarding it's structure and use? BOTTOM LINE: I would like to run some actionscript in the onSubmit event that would test for the existence of validation errors before running a flash remoting call. |
| Sponsored Links |
|
|||
|
The older entries at asfusion.com are a very good resource for all things
cfform/flash related. The Flex documentation is also useful. http://www.asfusion.com/blog/entry/e...-validation-in http://livedocs.adobe.com/flex/15/as...Validator.html I do not do much work with cfform/flash. But here is a small example demonstrating the onError method. It is not meant to do anything but show the error object properties. As it uses cfformitem type="script" it requires MX 7.02+ (IIRC). <!--- onError example ---> <cfform name="form1" format="flash" onError="doOnError(errors);" width="500" height="300"> <cfformitem type="script"> function doOnError(errors:Object):Void { var msg:String = ""; // for each error for (var key in errors) { // retrieve current error object var err = errors[key]; // display error object properties msg += "NAME ="+ err['name'] +"\n"; msg += "FIELD ="+ err['field'] +"\n"; msg += "VALUE ="+ err['value'] +"\n"; msg += "MESSAGE ="+ err['message'] +"\n\n"; } alert("Inside doOnError function\n\n"+ msg); } </cfformitem> <cfformgroup type="horizontal"> <cfinput type="text" name="firstname" label="First Name:" value="" required="true" validateat="onSubmit" validate="noblanks"> <cfinput type="text" name="lastname" label="Last Name:" value="" required="true" validateat="onSubmit" validate="noblanks"> <cfinput type="submit" label="Submit Form" name="submitButton" value="Submit Form"> </cfformgroup> </cfform> <!--- onSubmit ---> <cfform name="yourFormName" format="flash" width="500" height="300" onSubmit="return doSomethingOnSubmit();"> <cfformitem type="script"> function doSomethingOnSubmit() { // check for one or more errors var isFormValid = mx.validators.Validator.isStructureValid(this, 'yourFormName'); // if no errors found if ( isFormValid ) { // do whatever code here } else { alert("Inside doSomethingOnSubmit function:\n Errors found. Do something here."); } // if true, the form will be submitted. return isFormValid; } </cfformitem> <cfformgroup type="horizontal"> <cfinput type="text" name="firstname" label="First Name:" value="" required="true" validateat="onSubmit" validate="noblanks"> <cfinput type="submit" label="Submit Form" name="submitButton" value="Submit Form"> </cfformgroup> </cfform> |
|
|||
|
Thank you, mysterious stranger who roves the forums seeking programmers in
distress! That certainly helps me get half-way there. What I would like to do is "submit" the form using a flash remoting call attached to a button's onClick event. With the "isStructureValid" method you have shown me, I am able to stop the remoting call if there are errors (half my problem), but I am not sure how to produce an alert listing all the error messages. CFFORM produces this alert automatically if you actually submit the form, but I am not really submitting it. Is there a way to access this collection or errors outside of the onError method (which only seems to fire if you submit the form via the traditional method)? Thanks! |
|
|||
|
The are tons of comments in the asfusion link above, but check the one by Laura
(dated August 22, 2005 at 9:28 PM). She mentions: "If you want to completely emulate the way cfform does it by default, call userOnError() (although it is one of those hacks that may change in the future)". You can view the userOnError function code, by http://www.coldfusionusers.com/blog/index.php/2006/07/. It uses CFFormValidators.getInValidFields() to retrieve the error structure and display them in a pop-up. I do not how much of that is documented. But at least it gives you an idea how CF handles it. function userOnError(){ var errors = CFFormValidators.getInValidFields(); var msg = "<ul>"; for(var key in errors ) { msg += "<li>" +errors[key]['message'] +"</li>"; } msg += "<ul>" errorpopup = mx.managers.PopUpManager.createPopUp(this, FormErrorException, true, {message: msg}, true); errorpopup.centerPopUp(this); errorpopup.setFocus(); } |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise