Skip to content

Commit

Permalink
Bug fixed: update errors using tables fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcana committed May 24, 2020
1 parent cd74d46 commit 0180eb2
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
4 changes: 3 additions & 1 deletion js/app/parsers/dictionaryActions/arrayCreate.js
Expand Up @@ -22,8 +22,10 @@ ArrayCreate.prototype.updateDictionary = function( dictionary ){
var arrayValue = this.getValue( dictionary );

if ( this.indexToUse === -1 ){
this.resolvedIndex = arrayValue.length;
arrayValue.push( this.newElement );
} else {
this.resolvedIndex = this.indexToUse;
arrayValue.splice( this.indexToUse, 0, this.newElement );
}
};
Expand Down Expand Up @@ -52,7 +54,7 @@ ArrayCreate.prototype.updateHTML = function( indexItem, parserUpdater, actionIns
tags,
parentNode,
indexItem,
this.indexToUse
this.resolvedIndex
);

// Insert it
Expand Down
5 changes: 1 addition & 4 deletions js/app/parsers/parserNodeRenderer.js
Expand Up @@ -547,13 +547,10 @@ ParserNodeRenderer.configureNodeForNewItem = function( tmpNode, tags, parentNode
tmpNode.setAttribute( tags.qdup, 1 );

// Configure loop attributes
var itemIndex = indexToUse === -1?
parentNode.childElementCount - 1:
indexToUse;
Loop.setAutoDefineAttribute(
tmpNode,
indexItem.attributeInstance.getVarName(),
itemIndex,
indexToUse,
indexItem.attributeInstance.getExpressionString(),
parentNode.childElementCount,
0
Expand Down
54 changes: 54 additions & 0 deletions test/js/app/update.js
Expand Up @@ -3755,6 +3755,60 @@ QUnit.test( "Update array and array deleting TALRepeat test", function( assert )
testFunction( 'John/Peter/Luke/Michael/Lars', 'The number 1/The number 2/The number 3/The number 4/The number 6' );
});

QUnit.test( "insert object element by index = '_last_' with attributes TALRepeat test", function( assert ) {

var testNumber = 53;
var dictionary = {};
dictionary[ 'items' + testNumber ] = [
{
name: 'John',
description: 'The number 1'
},
{
name: 'Peter',
description: 'The number 2'
},
{
name: 'Luke',
description: 'The number 3'
}
];

errorsArray = undefined;

zpt.run({
root: document.getElementById( 't' + testNumber ),
dictionary: dictionary
});

var testFunction = function(){
assert.equal( utils.getAllValues( '.itemName' + testNumber ), arguments[ 0 ] );
assert.equal( utils.getAllValues( '.itemDescription' + testNumber ), arguments[ 1 ] );
assert.equal( errorsArray, undefined );
};

testFunction( 'John/Peter/Luke', 'The number 1/The number 2/The number 3' );

var dictionaryActions = [
{
id: 'items' + testNumber,
action: 'createArray',
index: '_last_',
newElement: {
name: 'Dave',
description: 'The number 4'
}
}
];

zpt.run({
command: 'update',
dictionaryActions: dictionaryActions
});

testFunction( 'John/Peter/Luke/Dave', 'The number 1/The number 2/The number 3/The number 4' );
});

QUnit.test( "simple TALContent with indexExpressions = false test", function( assert ) {

var dictionary = {
Expand Down
14 changes: 14 additions & 0 deletions test/update.html
Expand Up @@ -699,5 +699,19 @@ <h2>Update array and array deleting TALRepeat</h2>
</li>
</ol>
</div>

<h2>Insert object element by index = '_last_' with attributes in table TALRepeat</h2>
<div id="t53">
<table>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
<tr data-repeat="item items53" data-attributes="class item/name">
<td data-content="item/name" data-attributes="class 'itemName53'">an item name</td>
<td data-content="item/description" data-attributes="class 'itemDescription53'">an item description</td>
</tr>
</table>
</div>
</body>
</html>

0 comments on commit 0180eb2

Please sign in to comment.