Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS Header Field Validation

Status
Not open for further replies.

Auggz

Programmer
Dec 22, 2005
12
US
I have a web form that contains two computed subforms on it. The two subforms are only viewable by the MIS department. My question is how can I run field validation on those two subforms without affecting the rest of the user community? I have mandatory fields on the two subforms that have to be completed by MIS staff only and I have tried having JS Header entries on the subforms to perform the validation which works but the problem is that they also run when a regular user edits the form making it impossible to submit the form because they cannot see the fields on the subforms while the document is performing field validation on those fields.
Someone has suggested to me to user Roles that will tell the field validation to run only when its a member of the MIS team editing the document. I have never used Roles in a web application and would like any help on how I can use Roles to achieve my goal or if there is another simpler way to handle my situation.
 
User roles are to my opinion the best way to go. You can also use the values from the user roles in a temp field to use as an 'if' condition in the JS too (Recommended to set the ID tag in the properties for the field under the HTML section). You will need to use a 'compute for display' field as a minimum, and read the users roles in when loading the document (@UserRoles is web compatible) and then check for the bracketed user role name in the JS script before the subform fields are are validated:

if (this.form.UserRoles.value == "[UserRoleName]")
{
// Perform the validation for the subform
// (If there could be more than one role pr user, loop
// through the values using an array or similar multi
// value object...)
}
// Continue default validations for all users

Brgds,

TrooDOS
 
Thanks for your prompt response.

I have this code on JS Header and it now checks the fields even with users who do not have MIS Role. Let me know what could be wrong with it:

/* Check if mandatory fields contains values */
/* The first part of code checks only on users with MIS Role on the database */

function ValidateFields()
{
if (this.form.UserRoles.value == "[MIS]")
if ((f.assignee[0].checked == false && f.assignee[1].checked == false) ||
f.task_dt.value == "" ||
f.task_assignee.value == "" ||
f.task_desc.options[f.task_desc.selectedIndex].text == "" ||
f.task_duration.value == "" )

/* Check mandatory fields for regular users */

f = document.forms[0];
if (f.dept.options[f.dept.selectedIndex].text == "" ||
f.category.options[f.category.selectedIndex].text == "" ||
f.requested_for.options[f.requested_for.selectedIndex].text == "" ||
f.sub.value == "" ||
f.desc.value == ""
)
{
alert("Please Enter: \n\n Department \n Category \n Requested For \n Subject \n Description \n\n Then submit this form!");
f.sub.focus();
}
else
{
f.submitbutton.disabled=true;
f.submit();
}
}


function CannotSave()
{
alert("You do not have priviledges to modify this information!");
}


Also was I supposed to make any other change on the DB? I created the MIS role on the DB and granted all the MIS staff the MIS role. Let me know if theres something else I nee to do inorder to get this to work.
 
You will need to add the field 'UserRoles' if not already done in the form (or in the Subform, preferable in the main form). Make this field 'Computed for display' or 'Computed when composed'. Set the computed value to be @UserRoles.

If current user has assigned a role, then this will populate the field, and it will be used within the code you wrote
if (this.form.UserRoles.value == "[MIS]") etc.

It is recommended to set the ID tag in the HTML tab in field properties for the new field.

Brgds,

TrooDOS
 
I have done all the above and the code still does not recognize the Role. The only thing I did not do is set the ID tag on the HTML tab field. What exactly do I need to set on the HTML tab and do you thing this is the reason why its still does not recognize the [MIS] Role
 
Well, the ID tag will make the field recognisable for JS, and was necessary in R5.

Make following test:
function ValidateFields()
{
window.alert("Role: " + this.form.UserRoles.value)
if (this.form.UserRoles.value == "[MIS]")
...

Use some alert boxes to see what responses are down in the JS code... Your sure that the value cannot be an array? In other words, more than one potential role???

Also make sure that the test is run on a server, with the ACL settings under the advanced tab is set to 'Enforce a consistent ACL across all replicas'



Brgds,

TrooDOS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top