Opened 10 years ago

Closed 7 years ago

#9716 closed defect (invalid)

[patch] [cla] DTL variables in attribute nodes not replaced when empty

Reported by: carpie Owned by: carpie
Priority: low Milestone: future
Component: DojoX DTL Version: 1.3.2
Keywords: Cc:
Blocked By: Blocking:

Description

When a DTL variable is used for an attribute of a node, (e.g. inside the "value" attribute for an input node), and the variable resolves to an empty string, then the DTL variable is not replaced. If the variable resolves to null, then the DTL variable is replaced with the string 'null'. A regular Dijit widget replaces both of these with an empty string. If the DTL variable is not an attribute value, then both cases work correctly. Here's an example (full example file attached):

dojo.declare("DijitWidget", [dijit._Widget, dijit._Templated],
{
   foo: '',
   bar: null, 
   templateString: '<div><div>Clear text: foo=${foo}, bar=${bar}</div>' +
      '<div>Attr Value: foo=<input value="${foo}" /></div>' +
      '<div>bar=<input value="${bar}" /></div></div>',
});

dojo.declare("DTLWidget", [dijit._Widget, dojox.dtl._DomTemplated],
{
   foo: '',
   bar: null,
   templateString: '<div><div>Clear text: foo={{ foo }}, bar={{ bar }}</div>' +
      '<div>Attr Value: foo=<input value="{{ foo }}" /></div>' +
      '<div>bar=<input value="{{ bar }}" /></div></div>',
});

The dijit widget displays: Clear text: foo=, bar= Attr Value: foo=[] bar=[]

Teh DTL widget shows: Clear text: foo=, bar= Attr Value: foo=[{{ foo }}] bar=[null]

Assuming the DTL widget should work like the Dijit widget, I created a patch that fixes the two issues. I'm new to this code base, so there may be more appropriate fixes.

The empty string issue is caused by the fact that in AttributeNode's render function (dom.js) if the current contents of the node is "" and the resolved value is "", then setAttribute is not called to overwrite the current attribute value of {{ foo }}. My patch checks for "" and allows setAttribute to be called. It may be more appropriate to call setAttribute only if getAttribute doesn't match the resolved value. I'll defer to the maintainer's knowledge of which would be less costly.

The null issue happens because a null gets returned from _Filter's resolvePath routine. There seems to be a check to convert null to an empty string in the for loop that loops through parts. However, in the case above, this loop is entered so the check is skipped. My patch performs the check (and conversion) at the point the return value is being returned. Again, there may be a more appropriate way. The patch is against r19854.

Hope this helps...

Lee Carpenter

Attachments (2)

dtl_empty_variable.html (1.4 KB) - added by carpie 10 years ago.
Issue demonstration
dtl_empty_variable.patch (725 bytes) - added by carpie 10 years ago.
Patch to resolve the issue

Download all attachments as: .zip

Change History (9)

Changed 10 years ago by carpie

Attachment: dtl_empty_variable.html added

Issue demonstration

Changed 10 years ago by carpie

Attachment: dtl_empty_variable.patch added

Patch to resolve the issue

comment:1 Changed 10 years ago by dante

Milestone: tbd1.5
Summary: DTL variables in attribute nodes not replaced when empty[patch] DTL variables in attribute nodes not replaced when empty

is there a CLA on file for you carpie? name?

comment:2 Changed 9 years ago by carpie

Yes, I have a CLA. Lee Carpenter.

comment:3 Changed 9 years ago by bill

Summary: [patch] DTL variables in attribute nodes not replaced when empty[patch] [cla] DTL variables in attribute nodes not replaced when empty

comment:4 Changed 9 years ago by bill

Milestone: 1.51.6

1.5 is released, moving remaining tickets to 1.6

comment:5 Changed 8 years ago by bill

Milestone: 1.6future

(sadly) punting seemingly abandoned ticket and meta tickets to future

comment:6 Changed 7 years ago by ben hockey

Owner: changed from Neil Roberts to carpie
Priority: highlow
Status: newpending

i tried to apply this patch but it seems to break several tests. do you have a patch against current trunk that doesn't introduce any new errors in the tests?

comment:7 Changed 7 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Note: See TracTickets for help on using tickets.