[Bese-devel] reducing amount of javascript code for form validation

Denys Rtveliashvili rtvd at mail.ru
Sat Jul 22 18:31:37 UTC 2006


> some fyi's...
> 
>         * used dojo.byId instead of document.getElementById
> 
> there's a macro named $ in the ajax branch for this
>  
>         What I did not yet:
>         * pulling common code into a separate static javascript file
>         (I am not
>         sure how to do it in a proper manner, because the javascript
>         should be
>         loaded only when there are UCW forms in the document)
> 
> you can stuff into a global js as much as you want and have the
> browser cache the js file for you. see
> per-application-parenscript.lisp especially in the ajax branch where
> it's full of stuff already. 

Thank you for the hint! As I see, it is possible to use some of the ajax
branch features to improve the code even more. What is unclear though is
how to do it in practice:

- On one hand, if my changes are used in original ucw branch that seems
to be good. But I do not know how to put them there.
- And maybe it is possible to put them into ajax branch too.
- But if I try to modify my changes to benefit from ajax branch
features, they will become incompatible with the original ucw branch,
won't they?

>         * pulling out generic code like a check if a number is between
>         two other
>         numbers (it would be laconic to write something like
>         isNumberBetween
>         (field.value, 2, 10);)
> 
> don't know what you mean here, but having an
> ( ucw.forms.validators.number.between field-id 10 20) does not seem to
> be that bad. again, the ajax branch has many similar constructs...

Well.. (ucw.forms.validators.number.between field-id 10 20) is a LISP
notation in the LISP code. It is eventually translated into JavaScript.
And that JavaScript code seems to be rather large. I think it is
possible to create a small library of useful functions and call them if
it is necessary. That would reduce page size and improve readability.

>         * fixing bugs which were found in the process
> 
> there's a pending form field patch by Marijn that fixes several bugs
> but it's being updated for the new infrastructure in the ajax branch
> that simplifies it.
>         * In the form-specific javascript the "form" variable is
>         global.
>         Theoretically, this can lead to very bad consequences if there
>         are more 
>         than one form on a page.
> 
> fixed in ajax: <ucw:script generates non-toplevel js unless asked for
> the opposite and it can also be asked to compile the parenscript at
> compile-time.

Does it mean, that these patches won't be put into original ucw branch
and will exist only in ajax branch?

Thank you,
Denys R




More information about the bese-devel mailing list