Commit 19c6b514be3e34b60e644f1a8ef32ff751f57e72
1 parent
ff37fcbb
KTS-2359
"Automatically fill document title from filename" Added an onchange option to the file input. Committed by: Megan Watson Reviewed by: Conrad Vermeulen git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7269 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
15 additions
and
1 deletions
plugins/ktcore/folder/addDocument.php
| ... | ... | @@ -86,18 +86,31 @@ class KTFolderAddDocumentAction extends KTFolderAction { |
| 86 | 86 | $aTypes[] = $oDocumentType; |
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | + | |
| 90 | + // Onchange gets the name of the file and inserts it as the document title. | |
| 91 | + $sFileOnchange = "javascript: | |
| 92 | + var arrPath=this.value.split('/'); | |
| 93 | + if(arrPath.length == 1){ | |
| 94 | + var arrPath=this.value.split('\\\'); | |
| 95 | + } | |
| 96 | + var name=arrPath[arrPath.length-1]; | |
| 97 | + var title=name.split('.'); | |
| 98 | + document.getElementById('document_name').value=title[0];"; | |
| 99 | + | |
| 89 | 100 | $oForm->setWidgets(array( |
| 90 | 101 | array('ktcore.widgets.file',array( |
| 91 | 102 | 'label' => _kt('File'), |
| 92 | 103 | 'description' => _kt('The contents of the document to be added to the document management system.'), |
| 93 | 104 | 'name' => 'file', |
| 94 | 105 | 'required' => true, |
| 106 | + 'onchange' => $sFileOnchange, | |
| 95 | 107 | )), |
| 96 | 108 | array('ktcore.widgets.string',array( |
| 97 | 109 | 'label' => _kt('Document Title'), |
| 98 | 110 | 'description' => sprintf(_kt('The document title is used as the main name of a document throughout %s™.'), APP_NAME), |
| 99 | 111 | 'name' => 'document_name', |
| 100 | 112 | 'required' => true, |
| 113 | + 'id' => 'document_name', | |
| 101 | 114 | )), |
| 102 | 115 | array('ktcore.widgets.entityselection',array( |
| 103 | 116 | 'label' => _kt('Document Type'), | ... | ... |
templates/ktcore/forms/widgets/file.smarty
| 1 | - <input type="file" name="{$name}" {if $has_id}id="{$id}"{/if} {if $options.width}size="{$options.width}"{/if}/> | |
| 1 | + <input type="file" name="{$name}" {if $has_id}id="{$id}"{/if} {if $options.width}size="{$options.width}"{/if} | |
| 2 | + {if $options.onchange}onchange="{$options.onchange}" {/if} /> | ... | ... |