Bug? Handling of attribute names and default values in forms in 2.61 ??
I have a piece of code that looks like below. It has worked for a few years now. After upgrading to 2.61 it doesn't any more. <input type="hidden" name="teachers:list:default" value=""> <dtml-call "REQUEST.set('teacherList', getAllTeachers())"> <dtml-in teacherList sort=title> <input type="checkbox" name="teachers:list" value="<dtml-var path>"<dtml-if selected> checked</dtml-if>> <a href="<dtml-var path>/manage_main">&dtml-title;</a><br> </dtml-in> I have tracked the problem to the default value always being added to the "teachers" list. meaning that my action method: def addTeacher(self, teachers): print teachers
['some/path', '']
Where I would expect:
['some/path']
Isn't that a new behaviour? And isn't it a bug? regards Max M
On Thu, 2003-11-13 at 12:01, Max M wrote:
I have a piece of code that looks like below. It has worked for a few years now. After upgrading to 2.61 it doesn't any more.
<input type="hidden" name="teachers:list:default" value="">
<dtml-call "REQUEST.set('teacherList', getAllTeachers())"> <dtml-in teacherList sort=title> <input type="checkbox" name="teachers:list" value="<dtml-var path>"<dtml-if selected> checked</dtml-if>>
<a href="<dtml-var path>/manage_main">&dtml-title;</a><br> </dtml-in>
I have tracked the problem to the default value always being added to the "teachers" list.
meaning that my action method:
def addTeacher(self, teachers): print teachers
['some/path', '']
Where I would expect:
['some/path']
Isn't that a new behaviour? And isn't it a bug?
Can you double check that it is actually the default value, and not a trailing empty line (I'm guessing that you are posting to 'addTeacher' from a form with a control like: '<textarea name="teachers:lines">...'). E.g, change the 'teachers:list:default' value to some other string, and see if that value propagates. Either way, as a robustness measure I would recommend adding some input checking to 'addTeacher', e.g.: def addTeacher( self, teachers ): """ Add one or more teachers. """ teachers = filter( None, teachers ) # strip empty lines # your processing here Tres. -- =============================================================== Tres Seaver tseaver@zope.com Zope Corporation "Zope Dealers" http://www.zope.com
Tres Seaver wrote:
Can you double check that it is actually the default value, and not a trailing empty line (I'm guessing that you are posting to 'addTeacher' from a form with a control like: '<textarea name="teachers:lines">...').
The complete content of the form is below, and it is very simple. I am very certain that it is not the problem. I have also checked that it isn't an extra checkbox that has been sneaking in there. I solved the problem by removing the line with the default value in the form, and changing the action method to:: def editTeachersAction(self, teachers=None, REQUEST=None): "Code" if not teachers: teachers = [] Which is a better way to do it anyway. But that still leaves the bug in the form handling of Zope. regards Max M #################### [<a href="edit">Back</a>]<br/><br/> <div class="primary_h1">Undervisere tilknyttet uv-forløbet</div> <br> <form action="editTeachersAction" method="post" name="form" tal:define="allTeachers here/users/getAllTeachers"> <input type="hidden" name="teachers:list:default" value=""> <span tal:repeat="teacher python:here.uddan_teacher.getSmartList(here, allTeachers)"> <input type="checkbox" name="teachers:list" value="path" tal:attributes="value teacher/path; checked teacher/selected"> <span tal:content="teacher/title">title</span><br> </span> <br> <br> <input type="submit" value=" Gem "> </form>
E.g, change the 'teachers:list:default' value to some other string, and see if that value propagates.
Either way, as a robustness measure I would recommend adding some input checking to 'addTeacher', e.g.:
def addTeacher( self, teachers ):
""" Add one or more teachers. """ teachers = filter( None, teachers ) # strip empty lines # your processing here
Tres.
Max M wrote at 2003-11-13 18:01 +0100:
... <input type="hidden" name="teachers:list:default" value=""> ... <input type="checkbox" name="teachers:list" value="<dtml-var path>"<dtml-if selected> checked</dtml-if>> ... I have tracked the problem to the default value always being added to the "teachers" list.
You are right! You found a bug. The easiest way to reproduce it is as follows: showRequest: <html><body><dtml-var REQUEST></body></html> Visit the URL: "http://<yourZope>/showRequest?a:list:default=a&a:list=b". The result will be "form: a --> ['b','a']". Please file a bug report. -- Dieter
participants (3)
-
Dieter Maurer -
Max M -
Tres Seaver