Process Mapping Logo

Process Mapping - Forums

Sharing 19 years of knowledge and experience

 
Metastorm BPM forums
Sign up Latest Topics
 
 
 


Reply
  Author   Comment  
sam2000

Member
Registered:
Posts: 35
Reply with quote  #1 
Hi,

I want to do validation of some fields on click of submit button of form. I think, I need to write validation code in client extension of form. Moreover, how do i prevent the form being submitted if validation fails?
0
Rob_B

Veteran
Registered:
Posts: 109
Reply with quote  #2 
if you are writing validation code in the client extension, it is not a server event?

If you can validate your data client side, simply call it from the OnSubmit and return true or false from your script; false will prevent submission

it might also be nice to inform your users as to why the form won't go...

(c;


__________________
There are, essentially, three types of mathematician; those who can count, and those who can't
0
sam2000

Member
Registered:
Posts: 35
Reply with quote  #3 
Thanks Rob,

I wrote the validation client script in client extension of the form, returned true/false as you said, and it worked. The form doesn't submit if validation fails.

However, I am trying the achieve the same by using button (type=server button). I am calling client validation script from button's client's extension and returning true/false. This worked for form, but doesn't work for server button. The server code always executes on button click, even if the validation fails (returns false). Any idea?



0
Jerome

Avatar / Picture

Guru
Registered:
Posts: 5,507
Reply with quote  #4 
I make the JScript client script fail by executing an invalid statement such as:

invalid = "fff";

where invalid is not declared. It's a hack, and I think there is a better way documented elsewhere here, but it works.

__________________
Post an example, and we will have a much better idea what the problem is. In about 90% of posts, the problem is one of communication. Examples bridge that gap.
0
sam2000

Member
Registered:
Posts: 35
Reply with quote  #5 
This hack would produce javascript errors on client machine, which is not good. Looking for better and correct way.
0
mohnshine

Avatar / Picture

Senior Veteran
Registered:
Posts: 270
Reply with quote  #6 
You could add a client side button that runs the validation, and then if the validation succeeds, programmatically click the server side button.

If you do this, you would want to hide the server side button from the user.

The code needed to programmatically click the button follows (I prefer the first version as it is event driven):

function ClickAButton(btnName)
{
    try
    {
        var btn = document.getElementById(btnName);
        if(btn==null) return;
        // gain focus on button to ensure consistent Metastorm Client Results
        var nefocus = document.createEventObject();
        btn.fireEvent("onfocus", nefocus);
        // click button
        var neclick = document.createEventObject();
        btn.fireEvent("onclick", neclick);
    }
    catch (ex) {alert(ex.description);}
}

or
 
function ClickAButton(btnName)
{
    try
    {
        eworkData.FieldByName(btnName).HTMLfield.onfocus();
        eworkData.FieldByName(btnName).HTMLfield.onclick();
    }
    catch (ex) {alert(ex.description);}
}


__________________
Your best practice does not conform with my best practice.
0
sam2000

Member
Registered:
Posts: 35
Reply with quote  #7 
Hi Mohnshine,

Is there a way without using another client button? I want to put both client code and server code on the same button. Is there a way out?

0
mohnshine

Avatar / Picture

Senior Veteran
Registered:
Posts: 270
Reply with quote  #8 

Well you could try something similar to what Jerome suggested but instead of putting an invalid statement in the code, throw an error instead

if(ValidationFails) throw "Validation Error";

If you use the throw statement, don't wrap it in a try/catch unless you want to catch the error you are throwing.


__________________
Your best practice does not conform with my best practice.
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:


Create your own forum with Website Toolbox!