Simon Willison wrote:
> 
> 
> On 17 Nov 2005, at 23:04, Christopher Lenz wrote:
> 
>> I don't agree, at least for the common cases such as validating 
>> emails, URLs, date/time fields etc. It really shouldn't be  necessary
>> to call back to the server for trivial and/or common  validation tasks.
> 
> 
> I don't understand why not. It's hardly a performance burden (the 
> amount of data being transferred is trivial) and it makes things on  the
> client incredibly simple as the validation logic for one field  (send to
> the server, see what it says) is reusable for every other  field.
> Premature optimisation is the root of all evil.
> 
> If I get some spare time soon I think I'll build the Ajax-only 
> validation thing as a proof of concept. I'm willing to bet that the 
> performance difference between it and pure client-side validation  will
> be imperceptible in most cases. If it's noticable and obvious  that the
> user experience would be better with hybrid client-side/Ajax  validation
> then I'll throw my support firmly behind that option.
> 

It would be pretty easy to use AJAX by default, and client side stuff as
an alternative, eg

@client_side('path/to/script', 'js_function')
def my_validator(args):
    .....

def client_side(path, func_name):
    def _dec(func):
        func.js_path = path
        func.js_func_name = func_name
        return func
    return dec

And then whatever bit of code generates the javascript for the ajax can
utilise these function attributes.

So everything works via AJAX by default, but people can easily add in
client side overrides.

But of course if there is no point in doing this performance wise, we
shouldn't bother.

---
Usual "We all know how to use decorators in python <2.4" disclaimers apply.

Reply via email to