Hi Matt,
At 02:14 PM 22/06/2004 -0400, Matt Feifarek wrote:
CLIFFORD ILKAY wrote:
... in the writeContent() method
if self.form.fname.error():
self.writeln('''\t<tr><td class="errorLabel">Please enter a first name</td>''')
self.writeln('''\t<td class="errorField">%s</td></tr>''' % self.form.fname.tag())
else:
self.writeln('''\t<tr><td>%s</td>''' % self.form.fname.label())
self.writeln('''\t<td>%s</td></tr>''' % self.form.fname.tag())
self.writeln('''\t<tr><td>%s</td>''' % self.form.mname.label())
self.writeln('''\t<td>%s</td></tr>''' % self.form.mname.tag())
if self.form.lname.error():
self.writeln('''\t<tr><td class="errorLabel">Please enter a last name</td>''')
self.writeln('''\t<td class="errorField">%s</td></tr>''' % self.form.lname.tag())
else:
self.writeln('''\t<tr><td>%s</td>''' % self.form.lname.label())
self.writeln('''\t<td>%s</td></tr>''' % self.form.lname.tag())Some comments:
In FK there is already stuff for error formatting. For example, if there's an error, the input tag will contain class="error" so you can mark that as "red" or something (look in the examples).
I saw that but I wanted to customize the layout of the incomplete form, i.e. I wanted the error string beside the fields, not above them, and I wanted more specific error messages. Having said that, it can get out of hand very quickly if you have a couple of error conditions you are testing for. You have to have a bunch of tests just to output the correct error string. I cannot think of a better way of doing it though in order to provide useful feedback to the user.
Also, it's easier on your typing if you make a short-name reference to the form object in your local name space, like "f = self.form". Then you can just do f.lname.tag().
Select, middle button click is quite fast too:) As you saw below, I used an alias for self.form in newForm. I prefer names that convey meaning even to those who may not be familiar with Python, or even programming for that matter.
But there's nothing "wrong" with what you're doing; there's just already some plumbing for some of it.
This seems to work though I have a couple of questions about it.
1. When I click on the Submit button, if I do not enter a Middle Name, the form will not POST successfully. That is strange considering that Middle Name is not mandatory. If I enter anything in Middle Name, the form will POST. The only difference I can see between Middle Name and the other fields is that it is not mandatory and as such, I do not test for an error condition. How can I get the form to POST with a blank Middle Name field?
Hmm. That shouldn't happen. It's possible that it's getting confused by the lack of a Validator set declaration in the constructor of your field. IE,
newForm.addField(Fields.TextField('mname',label="Middle Name"))
may have to be:
newForm.addField(Fields.TextField('mname', [ ], label="Middle Name"))
If that's the case, that's a bad bug on our parts. Send me your actual code and I'll take a look.
Setting an empty parameter for the error test made no difference. As soon as I put in some error test though, e.g. Validators.MaxLength(25) for middle name, the form posted properly. Speaking of MaxLength(), how does one specify the width of a text field in FormKit? I saw no obvious way to do it.
2. I am using SQLObject to map the PostgreSQL tables to Python objects. I have that part prototyped and working. Once I get past the hurdle above, I have to transfer the contents of the form fields above to the Person object attributes. According to the Class Reference, I think I should be using self.form.value(fieldName) to do this. e.g.
if self.form.isSuccessful(): newPerson = Person( firstName = self.form.value(fname), middleName = self.form.value(mname), lastName = self.form.value(lname), )
... where Person is a SQLObject class corresponding to a PostgreSQL table. Am I on the right track?
That will certainly work. Alternatively, you can poke at each field:
newPerson = Person( firstName = self.form.fname.value(), middleName = self.form.mname.value(), [etc] )
Or, better yet, just get the whole values bundle as a dictionary:
values = self.form.values()
newPerson = Person( firstName=values['fname'], middleName=values['mname'] ) etc...
The first or second option is probably more readily understood by someone who may be new to Python.
Regards,
Clifford Ilkay Dinamis Corporation 3266 Yonge Street, Suite 1419 Toronto, Ontario Canada M4N 3P6
Tel: 416-410-3326
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss