Re: Form patches
"Matt Schmidt" <[email protected]> Mon, 18 Sep 2006 13:13:50 -0400
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
Ok. I redid the output a little to use JS for the image type. Regarding my other reply to this (on which I forgot to CC the list...sorry), I was able to fix the problem of having more than one link-type generate more than one hidden field, which prevented the handlers from working. The javascript creates a hidden field and then submits the form. For speed's sake, I used MochiKit to manipulate the form. On 9/12/06, Jonathan Ellis <[email protected]> wrote: > On Tue, 12 Sep 2006 14:12:27 -0400, "Matt Schmidt" <[email protected]> > said: > > The image type requires a patch to spyceCompile.py because of the way > > the html image-submit works. It's just a one liner to strip out '.x' > > from the handlerid. It'd probably be better to splice the string, but > > I didn't feel like it. > > I don't have time to look at the code right now but it seems cleaner to > do something like this instead: > > // javascript > function parent_form(node) { > while (true) { > node = node.parentNode; > if (!node || node.nodeName == 'BODY') { > return null; > } > if (node.nodeName == 'FORM') { > return node; > } > } > } > > # python > return '<a href="#" onclick="parent_form(this).submit()"><img ...></a>' > > (You could put the javascript in util/handlers.js to avoid spitting it > out inline.) > > (Javascript is tested in FF and IE, you're welcome to have at it in > Opera or Safari but my guess is it will work fine there too.) > > -Jonathan > -- > C++ is history repeated as tragedy. Java is history repeated as farce. --Scott McKay > > -- Matt http://sloat.liek.us/ ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Spyce-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/spyce-users
form.py-20060918.patch
(application/octet-stream, 2.1 KB)
Index: form.py
===================================================================
--- form.py (revision 1178)
+++ form.py (working copy)
@@ -22,6 +22,7 @@
if self.getParent('form'):
raise 'Nested form tags are not allowed'
id = self._context['_current_form_id']
+ self.id = id
err = self._context.get('_validation_error', None)
if err and id in err:
invokeSingleton(self._api, spyceConfig.validation_render, err=err[id])
@@ -30,8 +31,8 @@
raise 'invalid method attribute value: '+method
if action is None:
action = self.getModule('request').uri_path()
- self.getOut().write('<form method="%s" action="%s"%s>' % (
- method, action, formatArgs(kwargs)) )
+ self.getOut().write('<form id="%s" method="%s" action="%s"%s>' % (
+ id, method, action, formatArgs(kwargs)) )
def end(self):
self.getOut().write('</form>')
@@ -40,22 +41,23 @@
handlers = {} # non-None so spyceCompile will handle handler attr
def syntax(self):
self.syntaxSingleOnly()
- def begin(self, with='button', **kwargs):
+ def begin(self, type='button', **kwargs):
self.parentRequired('form')
if 'name' in kwargs:
raise "invalid submit tag attribute 'name' (use handlers to set different actions for different submit buttons)"
id = '_submit' + self.getFullId()
- if with == 'button':
- html = '<input id="%s" name="%s" type="SUBMIT"%s>' % (id, id, formatArgs(kwargs),)
- else:
- # *** confirm needs work
- js = kwargs['onclick']
- js += '' # *** create hidden element w/ submit ID
+ if type == 'image':
+ html = '<a href="#" id="%s" onclick="formSubmit(this);"><img %s></a>' % (id, formatArgs(kwargs),)
+ elif type == 'link':
if 'value' in kwargs:
v = kwargs['value']
else:
v = 'Submit'
- html = '<a id="%s" href="" onclick="%s">%s</a>' % (id, js, v)
+ js = "formSubmit(this);"
+ html = '<a href="#" id="%s" onclick="%s">%s</a>' % (id, js, v)
+ else:
+ html = '<input id="%s" name="%s" type="SUBMIT"%s>' % (id, id, formatArgs(kwargs),)
+
self.getOut().write(html)
class form_hidden(spyceTagPlus):
form.js
(application/x-javascript, 484 B) - not displayed