Hi there,

In one of my app I need to deal with local files. First I tried using
INPUT(_type='text',...) to ask user to manually input the full path
name of a specific file, such as "C:\Program Files\Blah blah\foo
\bar.exe". Obviously no one likes to type that long string. So I came
up with this. Feel free to use it if you like.

class FILENAME_SELECTOR(DIV):
  '''
  Usage:
  In your controller:
    def action(): return {'':FORM(..., FILENAME_SELECTOR
(_name='the_name'), ...)}
  After submit, the file name is in request.vars.the_name (but in UTF8
encoding!)
  '''
  def __init__(self, *components, **attributes):
    name=attributes.get('_name','filename')
    components=[
      INPUT(_type='file',_name='_%s'%abs(hash(self)),
        _onchange="document.getElementById
('%s').value=this.value"%name),
      INPUT(_type='hidden',_name=name,_id=name),]
    super(FILENAME_SELECTOR,self).__init__(*components, **attributes)

Regards,
Iceberg
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to