summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Petsovits2008-06-24 19:18:13 (GMT)
committer Jakob Petsovits2008-06-24 19:18:13 (GMT)
commit993c67e01a570ffa1461fc5d0b8d624141fbf1a7 (patch)
treefb2e635c6ef8fd46476d829c0742df6431eeeb41
parentcbf405b141c311d8137f7514d573fafe2f67cf84 (diff)
Make JavaScript input validation work.
-rw-r--r--filefield.js17
-rw-r--r--filefield.module6
2 files changed, 8 insertions, 15 deletions
diff --git a/filefield.js b/filefield.js
index 409565a..1f8fc47 100644
--- a/filefield.js
+++ b/filefield.js
@@ -1,10 +1,10 @@
// $Id$
/**
- * Auto Attach standard client side file input validation
+ * Auto-attach standard client side file input validation.
*/
-Drupal.filefieldValidateAutoAttach = function() {
- $("input[@type='file']").change( function() {
+Drupal.behaviors.filefieldValidateAutoAttach = function(context) {
+ $("input[@type='file']", context).change( function() {
$('.filefield-js-error').remove();
/**
@@ -13,8 +13,9 @@ Drupal.filefieldValidateAutoAttach = function() {
if(this.accept.length > 1){
v = new RegExp('\\.(' + (this.accept ? this.accept : '') + ')$', 'gi');
if (!v.test(this.value)) {
- var error = 'The file ' + this.value + " is not supported.\n";
- error += "Only the following file types are supported: \n" + this.accept.replace(/\|/g, ' ');
+ var error = Drupal.t("The file @filename is not supported. \nOnly the following file types are supported: \n@extensions",
+ { '@filename' : this.value, '@extensions': this.accept.replace(/\|/g, ' ') }
+ );
alert(error);
// what do I prepend this to?
// .prepend($('<div class="filefield-js-error>"' + error + '</div>'));
@@ -29,9 +30,3 @@ Drupal.filefieldValidateAutoAttach = function() {
/* @todo */
});
}
-
-// Global killswitch
-if (Drupal.jsEnabled) {
- $(document).ready(Drupal.filefieldValidateAutoAttach);
-}
-
diff --git a/filefield.module b/filefield.module
index 8138cbe..32191ac 100644
--- a/filefield.module
+++ b/filefield.module
@@ -349,9 +349,7 @@ function theme_filefield_container_item($element) {
function filefield_file_upload_form(&$form, &$form_state, $field, $delta, $item = NULL) {
$form['#attributes']['enctype'] = 'multipart/form-data';
- //drupal_add_js('misc/progress.js');
- //drupal_add_js('misc/upload.js');
- //drupal_add_js(drupal_get_path('module', 'filefield') .'/filefield.js');
+ drupal_add_js(drupal_get_path('module', 'filefield') .'/filefield.js');
$id = 'filefield-'. $field_name_css .'-'. $delta .'-form';
@@ -402,7 +400,7 @@ function filefield_file_upload_process($element, $edit, &$form_state, $form) {
'!size' => format_size(file_upload_max_size()),
));
if (!empty($field['widget']['file_extensions'])) {
- $upload_description .= ' ' . t('Allowed extensions: %ext.', array(
+ $upload_description .= ' ' . t('Allowed extensions: %ext', array(
'%ext' => $field['widget']['file_extensions'],
));
}