07.04.2008
Register     Login      
 
Testimonials
Powered by Testify!
DotNetNuke Platinum Benefactor

We're happy to show our support for the DotNetNuke platform and community by contributing back to the project at the highest "Platinum" level.
Testimonials
It works! - Thank you so much for responding so quickly, I am in the middle of a 6 day all-nighter to get a project finished and I didn't think anyone would reply at this time of the day before the weekend! Cheers you have saved me a lot of time.
vortexmusic (via email)
Buck's Tip: The Poor Man's Read Only Form Control That Accepts Validation
Location: BlogsBuck Anderson    
Posted by: Buck Anderson 2/15/2008 1:36 AM
Have you ever had a need to make a form control read only and required? Well folks, it ain't gonna work. Here is a simple solution...

I occasionally find a need to make a form input control read only and required.

In the case below, I needed an input control that would act as a bucket for the Select1 controls value. The Category and Sub Category controls are being generated dynamically , from arrays, and I needed the input control to hold the value on saving of the form.

XMod Poor Man's Read Only Control with Validation 

In most cases, I would set this field as style.display='none' and make it invisible. But, in this case, I wanted the user to view the current sub category to ensure it was correct before submitting the form. You can imagine the havoc that would ensue if the user was able to change this value.

If you set the control to read only, and also have a need to validate the control, the validation will fail. It can't read the file.

Setting an Xmod control to read only and required

 

So, I needed an alternative and this solution works pretty well. I call it the Poor Man's Read Only Control.

DNNprofessor.com - Read only control that accepts validation

The first attempt worked well but, if I quickly slid my mouse, while trying to highlight the text, I could find a way to change a few of the characters.

To improve upon the method, I created a change to my CSS class called NormalTextBoxGray.

.NormalTextBoxGray {
    color: #666666;
    font-family: Verdana, Tahoma, Arial, Helvetica;
    font-weight: normal;
    font-size: 10px;
    line-height: 11pt;
    background-color: Whitesmoke;
    cursor: not-allowed;    
}

By changing the cursor to cursor: not-allowed; - I now have a workable solution and a read only control that accepts validation.

For more tips like this, visit me at DNNprofessor.com

Happy coding and enjoy the experience,
Buck

Copyright ©2008 Buck Anderson and DNNprofessor.com
Permalink |  Trackback

Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
       Terms Of Use      Privacy Statement      © 2004-2008 Kelly Ford