quick search:
 

Prefill document_id in folder_factories skin

Submitted by: Norbert
Last Edited: 2001-08-23

Category: CMF

Average rating is: 0.0 out of 5 (0 ratings)

Description:
Gives novice users one less worry when creating a new CMF document by pre-filling the document id tag.

Use this in your folder_factories skin


Source (Text):
<script language="JavaScript">
time_id = <dtml-var "_.int(ZopeTime())">;

function writeId() {

<dtml-in allowedContentTypes sort=Type>
if (document.create_doc.type_name[<dtml-var sequence-index>].checked) {
    string_id = '<dtml-var getId size=5 etc="" lower>';
    }
</dtml-in>

document.create_doc.id.value= string_id + '_' + time_id ;

}
</script>


# Add name="create_doc" to the FORM tag

<form name="create_doc" action="invokeFactory" method="POST">


# Make sure you use the same sort method as you used when 
# defining the javascript id's

 <dtml-in allowedContentTypes sort=Type>

# Add onClick="writeId()" to the radio elements

 <tr valign="top">
  <td> <input type="radio" name="type_name" value="&dtml-getId;" onClick="writeId()"
        id="cb_&dtml-sequence-index;" /> </td>

# Dinner's ready!

Explanation:
Zope inserts the current time as an integer as the value of
time_id in javascript.

The JS function writeId is called by a user's triggering of an
onClick event on each of the radio buttons.

By iterating over allowedContentTypes, Zope inserts each button id
(sequence-index) and the first couple of characters of its associated
document type (getId).

Finally: when an onClick events occurs, JS writes a combination of the
selected document type and the time into the text field at the bottom of
the page.

See this in action at http://www.attira.net


Comments:

No Comments