Opened 13 years ago

Closed 13 years ago

#1105 closed enhancement (wontfix)

Template vars dont parse arrays

Reported by: ktiedt@… Owned by: bill
Priority: high Milestone: 0.9
Component: Widgets Version: 0.3
Keywords: templates variables widgets DatePicker Cc: ktiedt@…
Blocked By: Blocking:

Description

ie... ${this.weekdays[0]} doesnt parse to Sunday

I modified the problem function... or atleast part of the problem and got it working... however I think its a hack... the fix I did was in bootstrap1.js, here is the entire function

dojo.evalProp = function(/*String*/ name, /*Object*/ object, /*Boolean?*/ create){

summary: Returns 'object[name]'. If not defined and 'create' is true, will return a new Object. description: Returns null if 'object[name]' is not defined and 'create' is not true. Note: 'defined' and 'exists' are not the same concept.

if(name.charAt(name.length-1)=="]"){ name is an array in object.... this makes dj_undef barf

var idx = name.substring(name.indexOf("[")+1,name.length-1); var name = name.substring(0,name.indexOf("[")) so we handle it ourselves.... name = object[name][idx]; if(typeof name != undefined){

return name;

}

}

return (object && !dj_undef(name, object) ? object[name] : (create ? (object[name]={}) : undefined)); mixed

}

like I said... its kind of a hack... maybe dj_undef needs modifying and the return line needs fixing to better accomodate arrays since object[name[index]] isnt a valid var/obj etc....

This is one step in attempting to fix the "first day of week" problem with DatePicker? since to do it... you have to have a variable way to build the top of the calendars

Change History (7)

comment:1 Changed 13 years ago by bill

Owner: changed from bill to sjmiles

Yeah, that is sort of hackish :-)

I think the evalProp() function is only supposed to work on "a.b.c" like patterns. The "prop" in "evalProp" means a property of the object.

But the question is, why does DomWidget::buildFromTemplate() call dojo.lang.getObjPathValue() rather than just calling eval()?

Scott, can you comment?

comment:2 Changed 13 years ago by sjmiles

Type: defectenhancement

I put getObjPathValue there so a.b.c patterns could be used where before only a.b was allowed. I did not use 'eval' right off the bat because I just in general don't like evaluating arbitrary code. I can't immediately think of any particular reason not to use eval there. I don't really have an overall view on the widget template code, I just made the above tweak to help somebody out.

comment:3 Changed 13 years ago by sjmiles

IMO, this should not be handled by modifying evalProp.

comment:4 Changed 13 years ago by sjmiles

Milestone: 0.40.5
Status: newassigned

Pushing this uphill because my instinct is that using 'eval' is open to abuse and I would rather delay this issue until the templating system as a whole is looked at. But if there is consensus that we should just use 'eval' here to allow more complex syntax, then it's easy to patch.

comment:5 Changed 13 years ago by tk

Just a note since I opened this... as it turns out, arrays wouldnt really have been a great way to do this... If nobody else thinks that Arrays are needed in templates, I see no reason to keep this open...

In reality... in the way I intended to use it.. its no more functional that leaving them blank and filling them in by JS later.

-Karl

comment:6 Changed 13 years ago by sjmiles

Owner: changed from sjmiles to bill
Status: assignednew

This is no longer my bailiwick, hope you don't mind Bill.

comment:7 Changed 13 years ago by Adam Peller

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.