4 Replies Latest reply on Oct 16, 2008 12:13 PM by Bob, Adobe Engineer

    Form Field Validation in CS3 Javascript

    Seth McGraw Level 1
      How can one accomplish form field(in custom UI)validation in CS3? I have a dialog that will require several entries and radio button selections. I need to validate 4 or 5 entries. One being the validation of a 5 digit number, and the remaining will only need to validate the existence of an entry.

      Ideas?

      I can upload the current code if needed.
        • 1. Re: Form Field Validation in CS3 Javascript
          Level 1
          It's difficult to do well in CS3.

          About the best you can do is use the onChange or onChanging (I don't recommend onChanging) callback to validate after the fact.

          In CS4, you can do wonders.

          Bob
          • 2. Re: Form Field Validation in CS3 Javascript
            Seth McGraw Level 1
            Let me know what's up with CS4...Our suites are going to be downloaded in a couple of weeks.
            • 3. Re: Form Field Validation in CS3 Javascript
              Seth McGraw Level 1
              Also can you explain the onChange in more detail. We are beginners with javascript. An example of the actual syntax would be great.

              Thanks
              • 4. Re: Form Field Validation in CS3 Javascript
                Level 1
                In ScriptUI's event model for CS4, you can intercept the keypresses prior to their getting to the text box. That means you can pretty much watch what happens and prevent the bad stuff.

                In CS3, there's no way to do that.

                Here's a quick sample that doesn't work well, but should give you an idea.

                vDemo = function() {
                var w = new Window( "dialog", "CS3 Validation Demo" );
                w.textBox = w.add( "edittext" );
                w.textBox.characters = 10;
                w.textBox.onChange = function() {
                if ( ( parseInt( this.text ).toString() == this.text ) && ( this.text.length == 5 ) ) {
                this.window.okButton.enabled = true;
                this.window.msg.text = "";
                } else { // then it's not a 5 digit integer
                this.window.msg.text = "Must be a 5 digit integer";
                this.window.okButton.enabled = false;
                }
                }
                w.textBox.onChanging = function() {
                this.onChange();
                }
                w.msg = w.add( "statictext" );
                w.msg.characters = 20;

                var g = w.add( "group" );
                g.alignChildren = ["right", "middle" ];
                w.okButton = g.add( "button", undefined, "OK");
                w.okButton.enabled = false;
                w.cancelButton = g.add( "button", undefined, "Cancel" );
                w.okButton.onClick = function() {
                this.window.textBox.onChange();
                if ( this.enabled ) {
                this.window.close( 1 );
                }
                }
                w.cancelButton.onClick = function() {
                this.window.close( 2 );
                }
                w.center();
                if ( w.show() == 1 ) {
                alert( "OK Clicked" );
                }
                }
                vDemo();