Page 1 of 1

Validating database-driven auto-complete values

Posted: Mon Mar 19, 2012 11:30 am
by rajeevkushwaha
I have a textbox that is bound to a database file to provide auto-complete choice values. As user starts to type in, matching values start to show up. However, user could go on typing without selecting a value from choices and press enter.

User may enter a value that does not exist in database (hence does not show in auto-complete choices) - In such cases, I want to validate and display an error message to user on client-side itself, without making a round trip to server for validating entered value. Please let me know how this can be achieved.

Re: Validating database-driven auto-complete values

Posted: Mon Mar 19, 2012 12:24 pm
by David
If you want to validate on the client-side, you would have to run a JavaScirpt function using the "onsubmit" event.

Re: Validating database-driven auto-complete values

Posted: Fri Apr 17, 2015 4:20 am
by Mark Smart
David wrote:If you want to validate on the client-side, you would have to run a JavaScirpt function using the "onsubmit" event.
Hi David,

I'm also trying to perform validation client-side and set an error indicator to display a message.
Would you please elaborate on your answer above, as I don't quite understand what you're advising.

Many thanks,

Mark

Re: Validating database-driven auto-complete values

Posted: Fri Apr 17, 2015 2:45 pm
by Scott Klement
Hi Mark,

I'm a bit confused by your reference to 'indicator', since they are an RPG concept, and this discussion was about client-side validation without making a trip back to the server. (Which, of course, is where the RPG code runs.)

On the screen (record-format) properties there's an event called 'onsubmit':
4-17-2015 1-32-32 PM.png
4-17-2015 1-32-32 PM.png (9.22 KiB) Viewed 732 times
Here you can write logic that will be run when the user tries to submit the screen back to the server. If the 'onsubmit' logic evaluates to false, it will cancel the submission... so this would be a good put code that checks the contents of the screen fields and prevent them from being submitted if something is wrong.

For example, you might create a 'validation.js' Javascript file and link it into your Genie start.html, or if you're using our batch session controller, place it in /www/your-instance/htdocs/profoundui/userdata/custom/js. In that file you could have a routine like this (this is just off the top of my head -- sorry if I make any syntax errors.)

Code: Select all

function validateScreen() {
    var val = get("MyFieldId");
    if ( val<3 || val>24 ) {
        pui.errorTip("MyFieldId", "Value must be 3-24", 0 );
        return false;
    }
    else {
        return true;
    }
}
Then have the 'onsubmit' property call this validateScreen() function:
4-17-2015 1-42-22 PM.png
4-17-2015 1-42-22 PM.png (9.68 KiB) Viewed 732 times
Now, before the screen is sent to the server, it will check the contents of a field (where the 'id' property is "MyFieldId") and will pop up an "error tip" (tooltip for error messages) showing the error (if there is one) and returning false to stop the screen being submitted to the server.

This is the sort of thing that David was referring to.

Re: Validating database-driven auto-complete values

Posted: Tue Apr 21, 2015 11:29 am
by Mark Smart
Scott,

Thank you very much for this example.
The indicator reference was down to my newbie status thinking that controls on screen need an equivalent "field" in the RPG code. Now, a week in, I know better. ;o)

Best regards,

Mark

Re: Validating database-driven auto-complete values

Posted: Tue Oct 10, 2017 8:41 am
by paksilv
Hi Scott,

is it possible to check, in the validation function of onsubmit event, if a button was pressed?

Re: Validating database-driven auto-complete values

Posted: Tue Oct 10, 2017 6:33 pm
by Scott Klement
The onsubmit function is passed an array of all of the variables that will be submitted to the server program. So if you have a response bound to a button (etc) you can check that from the onsubmit.