binding variable names containing dots

155 views
Skip to first unread message

J. David Beutel

unread,
Mar 15, 2012, 3:59:34 PM3/15/12
to agil...@googlegroups.com
Thanks for making the group!

I'm trying to use data-bind on a page with lists of input fields, e.g., names like "accountDistribution[2].percent".  I modified _parseBindStr to support quoted variable names containing punctuation, but it still doesn't work with dots.

So, I'm trying to debug with core_only.html and Firebug, but $.getScript() loads agility.js as a single line.  How do the developers debug it?

Without debugging, my best guess on the cause of the dot problem is, for binding an event handler, jQuery is treating the dot as a namespace (1.6.1 line 2581).  It looks like spaces would also be a problem, but I don't need spaces.

Now I'm thinking I might try to sanitize the event names by converting dot and space to dash.  But, it's a hack, and I don't know if it'll work.  I'd appreciate advice.

Cheers,
11011011

Artur Adib

unread,
Mar 18, 2012, 9:30:15 AM3/18/12
to agil...@googlegroups.com
Hello David,

I'm not sure our current core_only.html is adequate. It doesn't work
without a server, and it's hard to debug as you pointed out. I
personally simply copy the desired test to a file like playground.html
and debug there (since the tests are all independent, you just have to
copy the corresponding block of code).

I'm open to ideas on how to fix/improve core_only! :)

As for binding to dotted variables, can you please elaborate a bit
more on your use case? If it proves to be a common use case we will
likely have to support it, but as you already hinted we'd have to
think about its consequences beyond data-bind (for example, what types
of events do we fire with model.set(), etc).

Thanks!

--
Artur Adib
http://twitter.com/arturadib

J. David Beutel

unread,
Mar 19, 2012, 4:04:07 PM3/19/12
to agil...@googlegroups.com
I replied with this last night, but it doesn't seem to have come through, so I'm reposting to the web site.

I wound up running core_only by copying agility.js over the ../../agility.js soft-link, instead of setting up a server.  This isn't ideal, of course, because I need to recopy after every update.  I haven't tried to improve it, though.  (I wonder if a hard-link would work, although not it git I'd guess, or using "../../" in the browser?)

Next time I try to debug, I'll copy stuff to a special debugging file.  If I get an idea to improve it, I'll post, although I'd say that the larger automation that you already have is more important.

Regarding the dotted variable names, I haven't really used Agility yet, so I had thought that it would be important for the variable names to correspond with the names of input fields.  But now, that doesn't seem important:  I just change the dots and brackets to underscores for my variable names, using Agility as-is.  This simplifies using them in GSPs, too.  I also have error and style variables in JSON for input fields, so there's no 1-to-1 name correspondence, anyway.

I'm trying to use Agility mainly for binding of validation results.  My JSON has error variables containing HTML lists.  Now I think I'll need to add support for data-bindhtml, as I saw in an enhancement request.

I guess this isn't the intended use case for Agility.  The page I'm developing is basically static, and works without Javascript.  It's in a Grails app, and the page currently has content-oriented AJAX, which was simple to implement with a template, but the way it replaces the whole form on this page is too disruptive.  So, I'm converting it to data-oriented AJAX with Agility, where the form itself and almost all its input fields stay in place, while the validation from the server updates dependent displays and error messages throughout the form.  The initial form is generated by a GSP, so it's not the static Javascript that the Agility docs advocate.  The form includes jQuery combo-boxes, which seem to need to be initialized after Agility (to avoid creating duplicates).  I may run into more complications, when I try to add new list items containing combo-boxes.

In any case, I'm impressed with how simple Agility looks, and I hope that I can make it work for my use case.

Cheers,
11011011

J. David Beutel

unread,
Mar 19, 2012, 5:57:28 AM3/19/12
to agil...@googlegroups.com

Cheers,
11011011

Reply all
Reply to author
Forward
0 new messages