https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108375

Revision: 108375
Author:   yaron
Date:     2012-01-08 23:46:33 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
Added handling for new 'values dependent on' field parameter - this involved 
making some other changes to the code, including replacing the 'relation' and 
'attribute' parameters for the autocomplete API with just 'property', adding 
the 'origname' HTML attribute for inputs in multiple-instance templates, and 
creating the $sfgFieldProperties and $sfgDependentFields global variables.

Modified Paths:
--------------
    trunk/extensions/SemanticForms/SemanticForms.php
    trunk/extensions/SemanticForms/includes/SF_AutocompleteAPI.php
    trunk/extensions/SemanticForms/includes/SF_FormField.php
    trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
    trunk/extensions/SemanticForms/includes/SF_FormUtils.php
    trunk/extensions/SemanticForms/includes/forminputs/SF_ComboBoxInput.php
    
trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php
    
trunk/extensions/SemanticForms/includes/forminputs/SF_TextWithAutocompleteInput.php
    trunk/extensions/SemanticForms/libs/SemanticForms.js

Modified: trunk/extensions/SemanticForms/SemanticForms.php
===================================================================
--- trunk/extensions/SemanticForms/SemanticForms.php    2012-01-08 22:38:08 UTC 
(rev 108374)
+++ trunk/extensions/SemanticForms/SemanticForms.php    2012-01-08 23:46:33 UTC 
(rev 108375)
@@ -348,3 +348,5 @@
 # ##
 $sfgShowOnSelect = array();
 $sfgAutocompleteValues = array();
+$sfgFieldProperties = array();
+$sfgDependentFields = array();

Modified: trunk/extensions/SemanticForms/includes/SF_AutocompleteAPI.php
===================================================================
--- trunk/extensions/SemanticForms/includes/SF_AutocompleteAPI.php      
2012-01-08 22:38:08 UTC (rev 108374)
+++ trunk/extensions/SemanticForms/includes/SF_AutocompleteAPI.php      
2012-01-08 23:46:33 UTC (rev 108375)
@@ -22,20 +22,24 @@
                $params = $this->extractRequestParams();
                $substr = $params['substr'];
                $namespace = $params['namespace'];
-               $attribute = $params['attribute'];
-               $relation = $params['relation'];
+               $property = $params['property'];
                $category = $params['category'];
                $concept = $params['concept'];
                $external_url = $params['external_url'];
+               $baseprop = $params['baseprop'];
+               $basevalue = $params['basevalue'];
+               //$limit = $params['limit'];
 
-               if ( strlen( $substr ) == 0 ) {
+               if ( is_null( $baseprop ) && strlen( $substr ) == 0 ) {
                        $this->dieUsage( 'The substring must be specified', 
'param_substr' );
                }
 
-               if ( !is_null( $attribute ) ) {
-                       $data = self::getAllValuesForProperty( false, 
$attribute, $substr );
-               } elseif ( !is_null( $relation ) ) {
-                       $data = self::getAllValuesForProperty( true, $relation, 
$substr );
+               if ( !is_null( $baseprop ) ) {
+                       if ( !is_null( $property ) ) {
+                               $data = self::getAllValuesForProperty( 
$property, null, $baseprop, $basevalue );
+                       }
+               } elseif ( !is_null( $property ) ) {
+                       $data = self::getAllValuesForProperty( $property, 
$substr );
                } elseif ( !is_null( $category ) ) {
                        $data = SFUtils::getAllPagesForCategory( $category, 3, 
$substr );
                } elseif ( !is_null( $concept ) ) {
@@ -78,25 +82,27 @@
                                ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
                        ),
                        'substr' => null, // Once 1.17 becomes acceptable as 
dependency, use ApiBase::PARAM_REQUIRED
-                       'attribute' => null,
-                       'relation' => null,
+                       'property' => null,
                        'category' => null,
                        'concept' => null,
                        'namespace' => null,
                        'external_url' => null,
+                       'baseprop' => null,
+                       'basevalue' => null,
                );
        }
 
        protected function getParamDescription() {
                return array (
                        'substr' => 'Search substring',
-                       'attribute' => 'Attribute (non-page property) for which 
to search values',
-                       'relation' => 'Relation (page property) for which to 
search values',
+                       'property' => 'Semantic property for which to search 
values',
                        'category' => 'Category for which to search values',
                        'concept' => 'Concept for which to search values',
                        'namespace' => 'Namespace for which to search values',
                        'external_url' => 'Alias for external URL from which to 
get values',
-                       'limit' => 'Limit how many entries to return',
+                       'baseprop' => 'A previous property in the form to check 
against',
+                       'basevalue' => 'The value to check for the previous 
property',
+                       //'limit' => 'Limit how many entries to return',
                );
        }
 
@@ -107,7 +113,7 @@
        protected function getExamples() {
                return array (
                        'api.php?action=sfautocomplete&substr=te',
-                       
'api.php?action=sfautocomplete&substr=te&relation=Has_author',
+                       
'api.php?action=sfautocomplete&substr=te&property=Has_author',
                        
'api.php?action=sfautocomplete&substr=te&category=Authors',
                );
        }
@@ -116,7 +122,7 @@
                return __CLASS__ . ': $Id$';
        }
 
-       public static function getAllValuesForProperty( $is_relation, 
$property_name, $substring = null ) {
+       private static function getAllValuesForProperty( $property_name, 
$substring, $base_property_name = null, $base_value = null ) {
                global $sfgMaxAutocompleteValues;
 
                $values = array();
@@ -124,6 +130,11 @@
                $sql_options = array();
                $sql_options['LIMIT'] = $sfgMaxAutocompleteValues;
 
+               $property = SMWPropertyValue::makeUserProperty( $property_name 
);
+               $is_relation = ( $property->getPropertyTypeID() == '_wpg' );
+               $property_name = str_replace( ' ', '_', $property_name );
+               $conditions = array( 'p_ids.smw_title' => $property_name );
+
                if ( $is_relation ) {
                        $value_field = 'o_ids.smw_title';
                        $from_clause = $db->tableName( 'smw_rels2' ) . " r JOIN 
" . $db->tableName( 'smw_ids' ) . " p_ids ON r.p_id = p_ids.smw_id JOIN " . 
$db->tableName( 'smw_ids' ) . " o_ids ON r.o_id = o_ids.smw_id";
@@ -132,14 +143,30 @@
                        $from_clause = $db->tableName( 'smw_atts2' ) . " a JOIN 
" . $db->tableName( 'smw_ids' ) . " p_ids ON a.p_id = p_ids.smw_id";
                }
 
-               $property_name = str_replace( ' ', '_', $property_name );
-               $conditions = "p_ids.smw_title = '$property_name'";
+               if ( !is_null( $base_property_name ) ) {
+                       $base_property = SMWPropertyValue::makeUserProperty( 
$base_property_name );
+                       $base_is_relation = ( 
$base_property->getPropertyTypeID() == '_wpg' );
 
-               if ( $substring != null ) {
+                       $base_property_name = str_replace( ' ', '_', 
$base_property_name );
+                       $conditions['base_p_ids.smw_title'] = 
$base_property_name;
+                       $main_prop_alias = ( $is_relation ) ? 'r' : 'a';
+                       if ( $base_is_relation ) {
+                               $from_clause .= " JOIN " . $db->tableName( 
'smw_rels2' ) . " r_base ON $main_prop_alias.s_id = r_base.s_id";
+                               $from_clause .= " JOIN " . $db->tableName( 
'smw_ids' ) . " base_p_ids ON r_base.p_id = base_p_ids.smw_id JOIN " . 
$db->tableName( 'smw_ids' ) . " base_o_ids ON r_base.o_id = base_o_ids.smw_id";
+                               $base_value = str_replace( ' ', '_', 
$base_value );
+                               $conditions['base_o_ids.smw_title'] = 
$base_value;
+                       } else {
+                               $from_clause .= " JOIN " . $db->tableName( 
'smw_atts2' ) . " a_base ON $main_prop_alias.s_id = a_base.s_id";
+                               $from_clause .= " JOIN " . $db->tableName( 
'smw_ids' ) . " base_p_ids ON a_base.p_id = base_p_ids.smw_id";
+                               $conditions['a_base.value_xsd'] = $base_value;
+                       }
+               }
+
+               if ( !is_null( $substring ) ) {
                        $substring = str_replace( "'", "\'", strtolower( 
$substring ) );
-                       // utf8 conversion is needed in case MediaWiki is using
-                       // binary data storage
-                       $conditions .= " AND 
(REPLACE(LOWER(CONVERT($value_field USING utf8)),'_',' ') LIKE '" . $substring 
. "%' OR REPLACE(LOWER(CONVERT($value_field USING utf8)),'_',' ') LIKE '% " . 
$substring . "%')";
+                       // UTF-8 conversion is needed in case MediaWiki is using
+                       // binary data storage.
+                       $conditions[] = "REPLACE(LOWER(CONVERT($value_field 
USING utf8)),'_',' ') LIKE '" . $substring . "%' OR 
REPLACE(LOWER(CONVERT($value_field USING utf8)),'_',' ') LIKE '% " . $substring 
. "%'";
                }
 
                $sql_options['ORDER BY'] = $value_field;
@@ -147,12 +174,7 @@
                        $conditions, __METHOD__, $sql_options );
 
                while ( $row = $db->fetchRow( $res ) ) {
-                       if ( $substring != null ) {
-                               $values[] = str_replace( '_', ' ', $row[0] );
-                       } else {
-                               $cur_value = str_replace( "'", "\'", $row[0] );
-                               $values[] = str_replace( '_', ' ', $cur_value );
-                       }
+                       $values[] = str_replace( '_', ' ', $row[0] );
                }
                $db->freeResult( $res );
 

Modified: trunk/extensions/SemanticForms/includes/SF_FormField.php
===================================================================
--- trunk/extensions/SemanticForms/includes/SF_FormField.php    2012-01-08 
22:38:08 UTC (rev 108374)
+++ trunk/extensions/SemanticForms/includes/SF_FormField.php    2012-01-08 
23:46:33 UTC (rev 108375)
@@ -48,11 +48,11 @@
        }
 
        static function createFromDefinition( $fieldName, $inputName, 
$isMandatory, $isHidden, $isUploadable, $possibleValues, $isDisabled, $isList, 
$inputType, $fieldArgs, $allFields, $strictParsing ) {
-               // see if this field matches one of the fields defined for this
+               // See if this field matches one of the fields defined for this
                // template - if it is, use all available information about
                // that field; if it's not, either include it in the form or
                // not, depending on whether the template has a 'strict'
-               // setting in the form definition
+               // setting in the form definition.
                $the_field = null;
                foreach ( $allFields as $cur_field ) {
                        if ( $fieldName == $cur_field->getFieldName() ) {
@@ -333,10 +333,10 @@
                if ( ! array_key_exists( 'autocompletion source', $other_args ) 
) {
                        if ( $this->template_field->getPropertyType() == '_wpg' 
) {
                                $other_args['autocompletion source'] = 
$this->template_field->getSemanticProperty();
-                               $other_args['autocomplete field type'] = 
'relation';
+                               $other_args['autocomplete field type'] = 
'property';
                        } elseif ( array_key_exists( 'autocomplete', 
$other_args ) || array_key_exists( 'remote autocompletion', $other_args ) ) {
                                $other_args['autocompletion source'] = 
$this->template_field->getSemanticProperty();
-                               $other_args['autocomplete field type'] = 
'attribute';
+                               $other_args['autocomplete field type'] = 
'property';
                        }
                }
                // Now merge in the default values set by SFFormPrinter, if

Modified: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
===================================================================
--- trunk/extensions/SemanticForms/includes/SF_FormPrinter.php  2012-01-08 
22:38:08 UTC (rev 108374)
+++ trunk/extensions/SemanticForms/includes/SF_FormPrinter.php  2012-01-08 
23:46:33 UTC (rev 108375)
@@ -734,6 +734,7 @@
                                // 
=====================================================
                                } elseif ( $tag_title == 'field' ) {
                                        $field_name = trim( $tag_components[1] 
);
+                                       $fullFieldName = $template_name . '[' . 
$field_name . ']';
                                        // cycle through the other components
                                        $is_mandatory = false;
                                        $is_hidden = false;
@@ -853,6 +854,9 @@
                                                                
$possible_values = SFUtils::getAllPagesForConcept( $sub_components[1] );
                                                        } elseif ( 
$sub_components[0] == 'values from namespace' ) {
                                                                
$possible_values = SFUtils::getAllPagesForNamespace( $sub_components[1] );
+                                                       } elseif ( 
$sub_components[0] == 'values dependent on' ) {
+                                                               global 
$sfgDependentFields;
+                                                               
$sfgDependentFields[$sub_components[1]] = $fullFieldName;
                                                        } elseif ( 
$sub_components[0] == 'property' ) {
                                                                
$semantic_property = $sub_components[1];
                                                        } elseif ( 
$sub_components[0] == 'default filename' ) {
@@ -862,7 +866,7 @@
                                                                
$field_args['default filename'] = $default_filename;
                                                        } elseif ( 
$sub_components[0] == 'restricted' ) {
                                                                $is_restricted 
= !array_intersect(
-                                                                               
$wgUser->getEffectiveGroups(), array_map( 'trim', explode( ',', 
$sub_components[1] ) )
+                                                                       
$wgUser->getEffectiveGroups(), array_map( 'trim', explode( ',', 
$sub_components[1] ) )
                                                                );
                                                        }
                                                }
@@ -1070,6 +1074,7 @@
                                                        // 'num' will get 
replaced by an actual index, either in PHP
                                                        // or in Javascript, 
later on
                                                        $input_name = 
$template_name . '[num][' . $field_name . ']';
+                                                       $field_args['origName'] 
= $template_name . '[' . $field_name . ']';
                                                } else {
                                                        $input_name = 
$template_name . '[' . $field_name . ']';
                                                }
@@ -1120,7 +1125,13 @@
                                                if ( $semantic_property != null 
) {
                                                        
$form_field->template_field->setSemanticProperty( $semantic_property );
                                                }
+                                               $semantic_property = 
$form_field->template_field->getSemanticProperty();
+                                               if ( !is_null( 
$semantic_property ) ) {
+                                                       global 
$sfgFieldProperties;
+                                                       
$sfgFieldProperties[$fullFieldName] = $semantic_property;
+                                               }
 
+
                                                // call hooks - unfortunately 
this has to be split into two
                                                // separate calls, because of 
the different variable names in
                                                // each case

Modified: trunk/extensions/SemanticForms/includes/SF_FormUtils.php
===================================================================
--- trunk/extensions/SemanticForms/includes/SF_FormUtils.php    2012-01-08 
22:38:08 UTC (rev 108374)
+++ trunk/extensions/SemanticForms/includes/SF_FormUtils.php    2012-01-08 
23:46:33 UTC (rev 108375)
@@ -13,6 +13,7 @@
 class SFFormUtils {
        static function setGlobalJSVariables( &$vars ) {
                global $sfgAutocompleteValues, $sfgAutocompleteOnAllChars;
+               global $sfgFieldProperties, $sfgDependentFields;
                global $sfgScriptPath;
 //             global $sfgInitJSFunctions, $sfgValidationJSFunctions;
                global $sfgShowOnSelect;
@@ -21,6 +22,8 @@
                $vars['sfgScriptPath'] = $sfgScriptPath;
                $vars['sfgAutocompleteValues'] = $sfgAutocompleteValues;
                $vars['sfgShowOnSelect'] = $sfgShowOnSelect;
+               $vars['sfgFieldProperties'] = $sfgFieldProperties;
+               $vars['sfgDependentFields'] = $sfgDependentFields;
 //             $vars['sfgInitJSFunctions'] = $sfgInitJSFunctions;
 //             $vars['sfgValidationJSFunctions'] = $sfgValidationJSFunctions;
                $vars['sfgFormErrorsHeader'] = wfMsg( 'sf_formerrors_header' );

Modified: 
trunk/extensions/SemanticForms/includes/forminputs/SF_ComboBoxInput.php
===================================================================
--- trunk/extensions/SemanticForms/includes/forminputs/SF_ComboBoxInput.php     
2012-01-08 22:38:08 UTC (rev 108374)
+++ trunk/extensions/SemanticForms/includes/forminputs/SF_ComboBoxInput.php     
2012-01-08 23:46:33 UTC (rev 108375)
@@ -76,6 +76,9 @@
                        'autocompletesettings' => $autocompletionSource,
                        'comboboxwidth' => $pixel_width,
                );
+               if ( array_key_exists( 'origName', $other_args ) ) {
+                       $selectAttrs['origname'] = $other_args['origName'];
+               }
                if ( array_key_exists( 'existing values only', $other_args ) ) {
                        $selectAttrs['existingvaluesonly'] = 'true';
                }

Modified: 
trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php
===================================================================
--- 
trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php
     2012-01-08 22:38:08 UTC (rev 108374)
+++ 
trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php
     2012-01-08 23:46:33 UTC (rev 108375)
@@ -113,6 +113,9 @@
                        $textarea_attrs['style'] = 'width: 100%';
                }
 
+               if ( array_key_exists( 'origName', $other_args ) ) {
+                       $inputAttrs['origName'] = $other_args['origName'];
+               }
                if ( !is_null( $remoteDataType ) ) {
                        $textarea_attrs['autocompletedatatype'] = 
$remoteDataType;
                }

Modified: 
trunk/extensions/SemanticForms/includes/forminputs/SF_TextWithAutocompleteInput.php
===================================================================
--- 
trunk/extensions/SemanticForms/includes/forminputs/SF_TextWithAutocompleteInput.php
 2012-01-08 22:38:08 UTC (rev 108374)
+++ 
trunk/extensions/SemanticForms/includes/forminputs/SF_TextWithAutocompleteInput.php
 2012-01-08 23:46:33 UTC (rev 108375)
@@ -39,12 +39,7 @@
        public static function getAutocompletionTypeAndSource( &$field_args ) {
                if ( array_key_exists( 'values from property', $field_args ) ) {
                        $autocompletionSource = $field_args['values from 
property'];
-                       $propValue = SMWPropertyValue::makeUserProperty( 
$autocompletionSource );
-                       if ( $propValue->getPropertyTypeID() == '_wpg' ) {
-                               $autocompleteFieldType = 'relation';
-                       } else {
-                               $autocompleteFieldType = 'attribute';
-                       }
+                       $autocompleteFieldType = 'property';
                } elseif ( array_key_exists( 'values from category', 
$field_args ) ) {
                        $autocompleteFieldType = 'category';
                        $autocompletionSource = $field_args['values from 
category'];
@@ -68,12 +63,7 @@
                        $autocompletionSource = $field_args['autocompletion 
source'];
                } elseif ( array_key_exists( 'semantic_property', $field_args ) 
) {
                        $autocompletionSource = 
$field_args['semantic_property'];
-                       $propValue = SMWPropertyValue::makeUserProperty( 
$autocompletionSource );
-                       if ( $propValue->getPropertyTypeID() == '_wpg' ) {
-                               $autocompleteFieldType = 'relation';
-                       } else {
-                               $autocompleteFieldType = 'attribute';
-                       }
+                       $autocompleteFieldType = 'property';
                } else {
                        $autocompleteFieldType = null;
                        $autocompletionSource = null;
@@ -164,6 +154,9 @@
                        'tabindex' => $sfgTabIndex,
                        'autocompletesettings' => $autocompleteSettings,
                );
+               if ( array_key_exists( 'origName', $other_args ) ) {
+                       $inputAttrs['origName'] = $other_args['origName'];
+               }
                if ( !is_null( $remoteDataType ) ) {
                        $inputAttrs['autocompletedatatype'] = $remoteDataType;
                }

Modified: trunk/extensions/SemanticForms/libs/SemanticForms.js
===================================================================
--- trunk/extensions/SemanticForms/libs/SemanticForms.js        2012-01-08 
22:38:08 UTC (rev 108374)
+++ trunk/extensions/SemanticForms/libs/SemanticForms.js        2012-01-08 
23:46:33 UTC (rev 108375)
@@ -82,7 +82,10 @@
            }
        });
 
-    values = sfgAutocompleteValues[field_string];
+    values = jQuery(this).data('autocompletevalues');
+    if ( !values ) {
+       values = sfgAutocompleteValues[field_string];
+    }
     if (values != null) {
        // Local autocompletion
 
@@ -96,12 +99,17 @@
                        return split(term).pop();
                }
 
+               var thisInput = jQuery(this);
+
                jQuery(this).autocomplete({
                        minLength: 0,
                        source: function(request, response) {
                                // We need to re-get the set of values, since
                                // the "values" variable gets overwritten.
-                               values = sfgAutocompleteValues[field_string];
+                               values = thisInput.data( 'autocompletevalues' );
+                               if ( !values ) {
+                                       values = 
sfgAutocompleteValues[field_string];
+                               }
                                response(jQuery.ui.autocomplete.filter(values, 
extractLast(request.term)));
                        },
                        focus: function() {
@@ -681,8 +689,11 @@
                function() {
                        // Add in a 'b' at the end of the name to reduce the
                        // chance of name collision with another field
-                       if (this.name)
+                       if (this.name) {
+                               var old_name = this.name.replace(/\[num\]/g, 
'');
+                               jQuery(this).attr('origName', old_name);
                                this.name = this.name.replace(/\[num\]/g, '[' + 
num_elements + 'b]');
+                       }
 
                        if (this.id) {
 
@@ -767,7 +778,7 @@
        // that doesn't involve removing and then recreating divs.
        new_div.find('.sfComboBoxActual').remove();
 
-       new_div.initializeJSElements();
+       new_div.initializeJSElements(true);
 
        // Initialize new inputs
        new_div.find("input, select, textarea").each(
@@ -792,12 +803,76 @@
 
 }
 
+// The first argument is needed, even though it's an attribute of the element
+// on which this function is called, because it's the 'name' attribute for
+// regular inputs, and the 'origName' attribute for inputs in multiple-instance
+// templates.
+jQuery.fn.setDependentAutocompletion = function( dependentField, baseField, 
baseValue ) {
+       propName = sfgFieldProperties[dependentField];
+       baseProp = sfgFieldProperties[baseField];
+       var myServer = wgScriptPath + "/api.php";
+       myServer += "?action=sfautocomplete&format=json&property=" + propName + 
"&baseprop=" + baseProp + "&basevalue=" + baseValue;
+       var dependentValues = [];
+       var thisInput = jQuery(this);
+       // We use jQuery.ajax() here instead of jQuery.getJSON() so that the
+       // 'async' parameter can be set. That, in turn, is set because
+       // if the 2nd, "dependent" field is a combo box, it can have weird
+       // behavior: clicking on the down arrow for the combo box leads to a
+       // "blur" event for the base field, which causes the possible
+       // values to get recalculated, but not in time for the dropdown to
+       // change values - it still shows the old values. By setting
+       // "async: false", we guarantee that old values won't be shown - if
+       // the values haven't been recalculated yet, the dropdown won't
+       // appear at all.
+       // @TODO - handle this the right way, by having special behavior for
+       // the dropdown - it should get delayed until the values are
+       // calculated, then appear.
+       jQuery.ajax({
+               url: myServer,
+               dataType: 'json',
+               async: false,
+               success: function(data) {
+                       realData = data.sfautocomplete;
+                       jQuery.each(realData, function(key, val) {
+                               dependentValues.push(val.title);
+                       });
+                       thisInput.data('autocompletevalues', dependentValues);
+                       thisInput.attachAutocomplete();
+               }
+       });
+}
+
 /**
+ * Called on a 'base' field (e.g., for a country) - sets the autocompletion
+ * for its 'dependent' field (e.g., for a city).
+ */
+jQuery.fn.setAutocompleteForDependentField = function( partOfMultiple ) {
+       curValue = jQuery(this).val();
+       if ( curValue == null ) { return this; }
+
+       nameAttr = partOfMultiple ? 'origName' : 'name';
+       name = jQuery(this).attr(nameAttr);
+       dependentField = sfgDependentFields[name];
+       if ( dependentField != null ) {
+               if ( partOfMultiple ) {
+                       jQuery(this).closest(".multipleTemplateInstance")
+                               .find('[origName="' + dependentField + '"]')
+                               .setDependentAutocompletion(dependentField, 
name, curValue);
+               } else {
+                       jQuery('[name="' + dependentField + '"]')
+                               .setDependentAutocompletion(dependentField, 
name, curValue);
+               }
+       }
+
+       return this;
+}
+
+/**
  * Initialize all the JS-using elements contained within this block - can be
  * called for either the entire HTML body, or for a div representing an
  * instance of a multiple-instance template.
  */
-jQuery.fn.initializeJSElements = function() {
+jQuery.fn.initializeJSElements = function( partOfMultiple ) {
        this.find(".sfShowIfSelected").each( function() {
                jQuery(this)
                .showIfSelected(true)
@@ -845,6 +920,20 @@
                'overlayColor'  : '#222',
                'overlayOpacity' : '0.8'
        });
+
+       this.find('input, select')
+               .setAutocompleteForDependentField( partOfMultiple )
+               .blur( function() {
+                       jQuery(this).setAutocompleteForDependentField( 
partOfMultiple );
+               });
+       // The 'blur' event doesn't get triggered for radio buttons for
+       // Chrome and Safari (the WebKit-based browsers) so use the 'change'
+       // event in addition.
+       // @TODO - blur() shuldn't be called at all for radio buttons.
+       this.find('input:radio')
+               .change( function() {
+                       jQuery(this).setAutocompleteForDependentField( 
partOfMultiple );
+               });
 }
 
 var num_elements = 0;
@@ -876,7 +965,7 @@
                        var id = select[0].id;
                        var curval = select[0].options[0].value;
                        curval = curval.replace('"', '"' );
-                       var input = jQuery("<input id=\"" + id + "\" 
type=\"text\" name=\" " + name + " \" value=\"" + curval + "\">")
+                       var input = jQuery("<input id=\"" + id + "\" 
type=\"text\" name=\"" + name + "\" value=\"" + curval + "\">")
                                .insertAfter(select)
                                .attr("tabIndex", select.attr("tabIndex"))
                                .attr("autocompletesettings", 
select.attr("autocompletesettings"))
@@ -917,6 +1006,7 @@
                                        minLength: 0
                                })
                        .addClass("ui-widget ui-widget-content ui-corner-left 
sfComboBoxActual");
+               input.attr("origname", select.attr("origname"));
                jQuery('<button type="button">&nbsp;</button>')
                        .attr("tabIndex", -1)
                        .attr("title", "Show All Items")


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to