Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.2.16

Request #5718 hierselect doesn't work with multiple forms containing same element names
Submitted: 2005-10-19 10:07 UTC
From: mhart at baselinesolutions dot com dot au Assigned: avb
Status: Closed Package: HTML_QuickForm
PHP Version: Irrelevant OS: irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2005-10-19 10:07 UTC] mhart at baselinesolutions dot com dot au
Description: ------------ Currently (as of QuickForm 3.2.5), if you have multiple QuickForms on a page that have hierselect elements of the same name, they won't function correctly because the namespace of the javascript arrays are limited to just the element names. For example, creating two forms, each with a hierselect element named 'filename' results in javascript from the second element that overwrites the values of the first element, because the _hr_options and _hr_defaults arrays for each form have the same index ('filename'). I've created a patch that I've linked to below that adds the form name to the beginning of the array index, hence making values unique across forms. Test script: --------------- Here is a patch that performs the namespace addition described above: http://www.baselinesolutions.com.au/patches/hierselect.php.patch Basically, the form name is captured during the onQuickFormEvent calls and then prepended to the indices of the _hr_options and _hr_defaults javascript arrays. Then there's a little bit of name mangling in the javascript to remove the form name from the front of these indices when the elements actually need to be accessed. Some issues to note: * I haven't tested this extensively at all - only on Windows XP with Firefox and IE, and only in a handful of situations. I don't know, for example, what happens when a form has no name. * If the form name is changed using QuickForm::updateAttributes after the element has been added, then it won't pick up the name change. I don't know if there's a way to pick up the form name in the toHtml method - but it didn't seem there was. * The form name is assigned on each 'updateValue' event - I don't know the inner workings of QuickForm enough to know if this is overkill, but it seemed the safest way to do it. It could just be done once if need be. * The form name is just prepended as is (after escaping). It may be nicer aesthetically to separate the form and element name with an underscore or similar - although this would require a little bit of extra code on the javascript side to unmangle. This scheme also implies that if one form name is a substring of another form name, there could be conflicts, but I'm not sure - this should probably be tested. If there are conflicts, then it's possible that another dimension needs to be added to the _hr_options and _hr_defaults arrays (ie, _hr_options[formName][elementName]). * I escape the form name each time it's needed for an array index - it could just be done once when it's assigned in onQuickFormEvent, assuming that it will only be used in javascript code.

Comments

 [2006-06-18 11:18 UTC] avb (Alexey Borzov)
Documented the need to have different names for hierselect elements. It is difficult to come up with the proper fix in current architecture, therefore this workaround should be used.