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.
Validating database-driven auto-complete values
-
- New User
- Posts: 7
- Joined: Mon Mar 05, 2012 5:29 pm
- First Name: Rajeev
- Last Name: Kumar
- Company Name: StoneRiver Inc
- Contact:
- David
- Profound Logic Staff Member
- Posts: 690
- Joined: Fri Jan 04, 2008 12:11 pm
- First Name: David
- Last Name: Russo
- Company Name: Profound Logic Software
- Contact:
Re: Validating database-driven auto-complete values
If you want to validate on the client-side, you would have to run a JavaScirpt function using the "onsubmit" event.
-
- Profound User
- Posts: 22
- Joined: Tue Apr 14, 2015 9:30 am
- First Name: Mark
- Last Name: Smart
- Company Name: Anker International
- Contact:
Re: Validating database-driven auto-complete values
Hi David,David wrote:If you want to validate on the client-side, you would have to run a JavaScirpt function using the "onsubmit" event.
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
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Validating database-driven auto-complete values
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':
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.)
Then have the 'onsubmit' property call this validateScreen() function:
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.
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':
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;
}
}
This is the sort of thing that David was referring to.
-
- Profound User
- Posts: 22
- Joined: Tue Apr 14, 2015 9:30 am
- First Name: Mark
- Last Name: Smart
- Company Name: Anker International
- Contact:
Re: Validating database-driven auto-complete values
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
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
-
- New User
- Posts: 11
- Joined: Thu Oct 20, 2016 5:56 am
- First Name: silvano
- Last Name: pacifici
- Company Name: VIBA SPA
- State / Province: Outside Canada/USA
- Country: Italy
- Contact:
Re: Validating database-driven auto-complete values
Hi Scott,
is it possible to check, in the validation function of onsubmit event, if a button was pressed?
is it possible to check, in the validation function of onsubmit event, if a button was pressed?
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Validating database-driven auto-complete values
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.
Who is online
Users browsing this forum: No registered users and 5 guests