-
Check for blanks
Frank,
Thanks for your help on my last validation example.
I now need to make sure that during an add that all fields are completed.
I am trying to use the on-line help but am confused on exactly which parameters to tweak.
Is there a good example of validating all fields are completed on an add record?
Thanks
Mike Becker
-
>>...during an add that all fields are completed
Seems like you want to make sure no fields are 'blank' during an 'Add' operation - correct? Try the following code and blank out the "Phone" and then hit submit.
FK
<script language="vb" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Dim Update As New Tornado.z
With Update
.dbUnit = 701
.dbMode = "ty=dual-horiz| sysind=t"
.dbSkin = 3
.dbDSN = "nwind.mdb"
.dbSQL = "Select * From employees"
.dbGridDisplayFlds = "0,1"
.dbValidatorParams = "code=/tornado/Jars|entry=false"
.dbEditUpdateFlds = "fi=0|ty=RONOUPdate,4,fi=HireDate|ty=TextCalendar, " & _
"fi=HomePhone|ty=TEXT|mask=USPHONE|event=both|req= true|err=Must be " & _
"XXX-XXX-XXXX,fi=ReportsTo|ty=SELECTBOX|val=EID|tex=FullNam e,fi=Notes|" & _
"type=TextArea|tag=COLS=25 ROWS=5"
.dbNavigationItem = "top,bottom,prev,next,update"
.dbBookMark = "employees;0"
.dbFormMagicCell = "fi=HireDate|macro=#Hiredate::d#"
.dbCommonTables = "index=EID,First,FullName|sql=Select employeeid,Firstname," & _
"Firstname & ' ' & Lastname from employees"
.dbLookUpFlds = "fi=EmployeeID|key=EID|look=FullName,fi=ReportsTo| key=EID|look=Fullname"
.dbTextHolder = "Title=Tornado Demo - Normal Update with Advanced Validation"
.ASPdbNET()
End With
End Sub
</script>
Last edited by Frank; 07-25-2007 at 01:51 PM.
-
validation continued
Frank,
Thanks. This works for text but I am using type =selectbox also.
The masks don't work for select box.
Do I have to use Javascript?
Mike
-
Mike,
Yes, SBOX does not work for the validator as I remember I tackle that problem before. So, you have a SBOX and the default is blank (no default value) and you want to make sure that user select a value? Have to use Js. I'll take a look and see what the problem is.
Fk
-
Enhancing Validator
Mike,
I looked at the code and it is very easy to add to the validator's Js to perform user validate. There are several way to do the advanced validation.
1. There is a very old never released feature (MyASPdbDLL) that allow user to write a DLL containing the validation code. All the form values are passed to the DLL and in return user can validate them. This is the most powerful and secure channel bur it takes a trip to the server and also kind of advanced as if the user DLL mess up then it'll not run.
2. We are looking into using the Ajax stuff to do validation plus a lot of Ajax wonderful stuff. When we get more comfortable with Ajax, we'll do that.
3. We can inject a new user Js feature to the validator and allow user to use Js to perform custom validation on top of the standard validator. I guess if enough examples are given, that will be the easiest way to go.
Let me know your thoughts.
Frank
-
blank records
Frank,
Ideally I would want control over all fields for no blank regardless of the type control for the data input. I have used JS with the classic aspdb and it is fine if there are good examples.
Lets go with the easiest since I have a deadline to get this completed by.
Thanks
Mike
-
OK.. I'll put in the hook and see whether it works.
Fk
-
Mike,
I got the solution. It is not pretty but very powerful as user have control to all the fields to validate. The problem is to identify the element to validate which is the index of the ASPDB_editaction_X_Y where editaction = ADD, UPDATE, DELETE and X = SQL index Y=grid row.
I'll let you try it and you let me know....
email me with your id file and what platform you are running on 1.1 or 2.0 and I'll build a test DLL for you.
Frank
-
I don't know what 1.1 or 2.0 is.
My id file I will e-mail you seperately.
Thanks
Mike
-
-
-
Sample code in Edit Add -> No-Blanks-Allowed
Mike,
The following code works w/o any new code. The difference is that the new hook is in the Validator. That means, you want to have full control at the same time using the Validator. The following code do not use the Validator and just use simple Js to check for blanks in the ADD operation and return false. I only code for 4 elements covering TEXT and SELECT.
Frank
Dim ujs As String = "<" & "script language='Javascript'>" & _
"function noblanks(thisform) {" & vbCrLf & _
"if (thisform.ASPDB_ADD_1_0.value == ''){" & _
"alert('LastName cannot be blank');return false;}" & _
"else if (thisform.ASPDB_ADD_2_0.value == ''){" & _
"alert('FirstName cannot be blank');return false;}" & _
"else if (thisform.ASPDB_ADD_3_0.value == ''){" & _
"alert('Title cannot be blank');return false;}" & _
"else if (thisform.ASPDB_ADD_4_0.options[thisform['ASPDB_ADD_4_0'].selectedIndex].value == ''){" & _
"alert('Title of Courtesy cannot be blank');return false;}" & _
"return true;}<" & "/script>"
Dim J As New Tornado.z
With J
.dbQP = "U=1| D=NWIND| Q=employees| S=8| gdf=0,1,2| Ni=b5, add| bm=employees;0| TH=title=No Blank in Add - User JS Validate"
.dbEditValidateName = "noblanks(this)"
.dbSendHead = ujs
.dbCommonTables = "Index=TOC|Value=Mr.,Mrs.,Ms.,Dr. ; index=EID,FullName|sql=Select employeeid, Firstname & ' ' & Lastname from employees"
.dbLookUpFlds = "fi=ReportsTo| key=EID|look=Fullname"
.dbEditAddFlds = "1,2,3,fi=4|Ty=Selectbox+B|Text=TOC|Val=TOC,5,6,7, 8,9,10,11,12," & _
"fi=ReportsTo|ty=SELECTBOX+B|val=EID|tex=FullName, fi=Notes|type=TextArea|tag=COLS=25 ROWS=5"
.ASPdbNET()
End With
Last edited by Frank; 08-09-2007 at 05:56 PM.
-
Add ID=fieldname tag to the Edit element
I have added an ID tag to Edit and GridEdit elements such that you can access the element via the following ->
"if (document.getElementById('LastName').value == ''){" & _
"alert('LastName cannot be blank');return false;}" & _
"else if (thisform.ASPDB_ADD_2_0.value == ''){" & _
"alert('FirstName cannot be blank');return false;}" & _
In order to access vis the ID, you need a recent browser that supports the getElementById which is the same requirement for all the AJAX stuff.
So, for normal edit, we now have ID=LastName and for Grid Edit, we have LastName_row. Much easier to work with.
Note: For foreign language installation and the fieldname is in foreign language, you MUST use the NAME like ASPDB_ADD_1_0 and not the Fieldname. This browser problem was the result of a very long debug session with a German user about 8 years ago and we discovered the debug.
See updated example below - The LastName and Notes fields are using the ID tag.
Frank
Dim ujs As String = "<" & "script language='Javascript'>" & _
"function noblanks(thisform) {" & vbCrLf & _
"if (document.getElementById('LastName').value == ''){" & _
"alert('LastName cannot be blank');return false;}" & _
"else if (thisform.ASPDB_ADD_2_0.value == ''){" & _
"alert('FirstName cannot be blank');return false;}" & _
"else if (thisform.ASPDB_ADD_3_0.value == ''){" & _
"alert('Title cannot be blank');return false;}" & _
"else if (thisform.ASPDB_ADD_4_0.options[thisform['ASPDB_ADD_4_0'].selectedIndex].value == ''){" & _
"alert('Title of Courtesy cannot be blank');return false;}" & _
"if (document.getElementById('Notes').value == ''){" & _
"alert('Notes cannot be blank');return false;}" & _
"return true;}<" & "/script>"
Dim J As New Tornado.z
With J
.dbQP = "U=1| D=NWIND| Q=employees| S=8| gdf=0,1,2| Ni=b5, add| bm=employees;0| TH=title=No Blank in Add - User JS Validate"
.dbEditValidateName = "noblanks(this)"
.dbSendHead = ujs
.dbCommonTables = "Index=TOC|Value=Mr.,Mrs.,Ms.,Dr. ; index=EID,FullName|sql=Select employeeid, Firstname & ' ' & Lastname from employees"
.dbLookUpFlds = "fi=ReportsTo| key=EID|look=Fullname"
.dbEditAddFlds = "1,2,3,fi=4|Ty=Selectbox+B|Text=TOC|Val=TOC,5,6,7, 8,9,10,11,12," & _
"fi=ReportsTo|ty=SELECTBOX+B|val=EID|tex=FullName, fi=Notes|type=TextArea|tag=COLS=25 ROWS=5"
.ASPdbNET()
End With
Last edited by Frank; 08-09-2007 at 05:57 PM.
-
User validation Js code for classic ASP-db
For the Classic ASP-db users, the following code is equivalent to the Tornado code in checking for blanks in Edit. Actually you can perform any kind of validation besides checking for blanks by using the Js functions.
<HTML><HEAD>
<script language='Javascript'>
function noblanks(thisform) {
if (thisform.LastName.value == ''){
alert('LastName cannot be blank');return false;}
else if (thisform.FirstName.value == ''){
alert('FirstName cannot be blank');return false;}
else if (thisform.title.value == ''){
alert('Title cannot be blank');return false;}
else if (thisform.TitleOfCourtesy.options[thisform['TitleOfCourtesy'].selectedIndex].value == ''){
alert('Title of Courtesy cannot be blank');return false;}
if (thisform.Notes.value == ''){
alert('Notes cannot be blank');return false;}
return true;}
</script>
</HEAD>
<BODY>
<Center><H3>This example illustrates User Validate Js in Classic ASP-db<BR></Center>
<%
Set X=Server.CreateObject("ASP.db")
with X
.dbUnit = 2006
.dbMode="dual-horiz"
.dbGridDisplayFlds="0,1,2"
.dbDSN = "NWIND"
.dbNavigationItem="top,bottom,prev,next,add"
.dbSQL="SELECT * FROM EMPLOYEES"
.dbEditFlds = "1,2,3,4,Notes"
.dbEditParams="Tablename=employees,bookmarkflds=0, EditValidateName=noblanks(this)"
.dbEditDropFlds="4,mdb=nwind.mdb,employees,titleof courtesy,,ADDNULL"
.aspdb
end with
%>
</BODY></HTML>
Last edited by Frank; 08-04-2007 at 09:21 PM.
-
Example in using Validator and User Js to check blank dropbox
You can cut/paste the following code into your VS WebForm or you can add the .aspx file header and footer to make it stand alone. The code illustrate user checking the drop box on top of the validator which does not cover drop boxes.
Dim ta As String = "<" & "script language='javascript'>" & vbCrLf
ta &= "function checkselect(thisform){" & vbCrLf
ta &= "if (thisform.ASPDB_UPDATE_16_0.options[thisform['ASPDB_UPDATE_16_0'].selectedIndex].value == '')" & vbCrLf
ta &= "{" & vbCrLf
ta &= "alert('ReportsTo Field cannot be Blank');" & vbCrLf
ta &= "return false;" & vbCrLf
ta &= "}" & vbCrLf
ta &= "else {return true;}" & vbCrLf
ta &= "}<" & "/script>" & vbCrLf
Dim Update As New Tornado.z
With Update
.dbUnit = 701
.dbMode = "ty=dual-horiz| sysind=t"
.dbSkin = 3
.dbDSN = "nwind.mdb"
.dbSQL = "Select * From employees"
.dbGridDisplayFlds = "0,1"
.dbValidatorParams = "code=/tornado/Jars|entry=false| UserValidateJs=checkselect(thisform)"
.dbEditUpdateFlds = "fi=0|ty=RONOUPdate,4,fi=HireDate|ty=TextCalen dar, " & _
"fi=HomePhone|ty=TEXT|mask=USPHONE|event=both|req= true|err=Must be " & _
"XXX-XXX-XXXX,fi=ReportsTo|ty=SELECTBOX+B|val=EID|tex=FullN ame,fi=Notes|" & _
"type=TextArea|tag=COLS=25 ROWS=5"
.dbNavigationItem = "top,bottom,prev,next,update"
.dbBookMark = "employees;0"
.dbFormMagicCell = "fi=HireDate|macro=#Hiredate::d#"
.dbCommonTables = "index=EID,First,FullName|sql=Select employeeid,Firstname," & _
"Firstname & ' ' & Lastname from employees"
.dbLookUpFlds = "fi=EmployeeID|key=EID|look=FullName,fi=Report sTo| key=EID|look=Fullname"
.dbTextHolder = "Title=Tornado Demo - Normal Update with Advanced Validation"
.dbSendHead = ta
.ASPdbNET()
End With
Last edited by Frank; 08-09-2007 at 05:58 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|