This topic is locked
[SOLVED]

 Make Fields "Read Only" or "Uneditable"

1/10/2010 2:10:11 PM
ASPRunnerPro General questions
C
codywallace author

I've learned how to make fields "disabled" by using the example in the Tip 6503-how-to-disableenable.... .
Now I would like to know if more advanced functionality exists that would allow for fields in an Edit form to be essentially "locked", based upon another field, so that whatever has been recorded in that field can no longer be changed.
For example, there is a master table for Orders:
Field1: Orders.OrderID [Number]

Field2: Orders.CustomerID [Number]

Field3: Orders.OrderDate [Date]

Field4: Orders.OrderDescription [Text]

Field5: Orders.OrderApproved [Dropdown List]

Field6: Orders.OrderShipped [Checkbox]

Field7: Orders.ShipDate [Date]

Field8: Orders.OrderComplete [Checkbox]
Once the Order has been created, it needs to be approved. Once approval is complete ("Yes" selected), the OrderDate and OrderDescription fields need to be locked so that they can no longer be modified. Later, when the OrderShipped checkbox is checked, the OrderApproved dropdown needs to be locked. Finally, when everything is complete, the OrderComplete checkbox gets ticked and all fields are locked.
I tried doing this with the "disable" javascript code but it resulted in those fields being erased when the record got saved since disabled fields do not get captured by Submit. I searched your forums and found reference to "readOnly" instead of "disable" and found that it worked on "Text" fields but not on checkboxes or dropdown lists. It halfway worked on dates because I was unable to type in the date field but the pop-up calendar would still change the date.
I'm hoping this in not an overly complicated thing to code. It would really be nice if ASPRunnerPro had some option built in where as you could select to disable and lock fields conditionally without having to manually code it.
Thanks again,
Cody <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=13525&image=1&table=forumtopics' class='bbc_emoticon' alt=':rolleyes:' />

J
Jane 1/12/2010

Cody,
disabled values should be saved in the database. Could you post code you use to set up these fields as disabled?

Or you can publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

C
codywallace author 1/13/2010

Dear Jane,
I went back and looked at my code again and realized that I had made a mistake and was clearing the fields when they became disabled with onchange. That was my fault and I've removed that code.
With the code being correct, all fields that have data recorded before being disabled do maintain that data except for date fields. Date fields only maintain the data for when they are initially disabled. Any edits after they are disabled result in the date fields being cleared out. Since the form I want to use is designed to track the order process up to the point of being shipped, there will be multiple edits.
Also, disabled fields with data in them are grayed out in Firefox and dimmed in IE. That doesn't really look nice. Is there a way to make these fields look like other fields while still being disabled? I guess what I am asking is if there is a to handle formatting through the JavaScript.
The code I am using is:

<script>

if(document.forms.editform.value_OrderApproved.value != 'Yes' )

{

document.forms.editform.value_OrderShipped.disabled=true;

document.forms.editform.value_ShipDate.disabled=true;

document.forms.editform.value_ShipName.disabled=true;

document.forms.editform.value_ShipAddress.disabled=true;

document.forms.editform.value_ShipCity.disabled=true;

document.forms.editform.value_ShipState.disabled=true;

document.forms.editform.value_ShipPostalCode.disabled=true;

document.forms.editform.value_ShipCountry.disabled=true;

document.forms.editform.value_OrderComplete.disabled=true;

}

else

{

document.forms.editform.value_OrderShipped.disabled=false;

document.forms.editform.value_ShipDate.disabled=false;

document.forms.editform.value_ShipName.disabled=false;

document.forms.editform.value_ShipAddress.disabled=false;

document.forms.editform.value_ShipCity.disabled=false;

document.forms.editform.value_ShipState.disabled=false;

document.forms.editform.value_ShipPostalCode.disabled=false;

document.forms.editform.value_ShipCountry.disabled=false;

document.forms.editform.value_OrderComplete.disabled=false;

}

</SCRIPT>
<script>

if(document.forms.editform.value_OrderApproved.value == 'Yes' )

{

document.forms.editform.value_CustomerID.disabled=true;

document.forms.editform.value_EmployeeID.disabled=true;

document.forms.editform.value_OrderDate.disabled=true;

document.forms.editform.value_OrderDescription.disabled=true;

}

else

{

document.forms.editform.value_CustomerID.disabled=false;

document.forms.editform.value_EmployeeID.disabled=false;

document.forms.editform.value_OrderDate.disabled=false;

document.forms.editform.value_OrderDescription.disabled=false;

}

</SCRIPT>
<script>

if(document.forms.editform.value_OrderComplete.checked)

{

document.forms.editform.value_OrderApproved.disabled=true;

document.forms.editform.value_OrderShipped.disabled=true;

document.forms.editform.value_ShipDate.disabled=true;

document.forms.editform.value_ShipName.disabled=true;

document.forms.editform.value_ShipAddress.disabled=true;

document.forms.editform.value_ShipCity.disabled=true;

document.forms.editform.value_ShipState.disabled=true;

document.forms.editform.value_ShipPostalCode.disabled=true;

document.forms.editform.value_ShipCountry.disabled=true;

}

else

{

document.forms.editform.value_OrderApproved.disabled=false;

document.forms.editform.value_OrderShipped.disabled=false;

document.forms.editform.value_ShipDate.disabled=false;

document.forms.editform.value_ShipName.disabled=false;

document.forms.editform.value_ShipAddress.disabled=false;

document.forms.editform.value_ShipCity.disabled=false;

document.forms.editform.value_ShipState.disabled=false;

document.forms.editform.value_ShipPostalCode.disabled=false;

document.forms.editform.value_ShipCountry.disabled=false;

}

</SCRIPT>


I've uploaded the project to Orders
To recreate the scenario, go to Orders and Add a new order. Go as far as you can then Save it. Then go back to list. Next Edit the same order and change the Order Approved to "Yes" then Save. At this point, the Order Date is disabled and still populated. Now check the Order Shipped box and then Save again. Now the Order Date field is blank. How do I overcome this?
Thanks