Testimonials Minimize
In less than 3 hours we had developed a store-like presentation that has a very easy to use admin and unlimited flexibility for the future. The XMod team has made one great product. We are looking forward to seeing what the future versions will bring.
Derek D. Gentry (Snowcovered Rating 5/5 Snowflakes)
  
spacer
DNNDev Blogs: Most recent blog entries Minimize
Feb 15

Written 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

Tags:

1 comment(s) so far...

Re: Buck's Tip: The Poor Man's Read Only Form Control That Accepts Validation

Great work Buck...

By Himanshu Joshi on   7/3/2009 6:31 AM

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
spacer
dummy