Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
fixed: remove any existing content from instances that have a src att…
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnR committed Apr 9, 2015
1 parent eda5f01 commit db1fd1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

[Unreleased]
---------------
##### Fixed
- remove existing content form external instances

[3.5.2] - 2015-04-08
---------------
##### Added
- support for current()

Expand Down
10 changes: 8 additions & 2 deletions src/js/FormModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ define( [ 'xpath', 'jquery', 'enketo-js/plugins', 'enketo-js/extend', 'jquery.xp
*/

function FormModel( modelStr, externalData, options ) {
var $model, id,
var $model, id, instanceDoc, instanceRoot,
that = this;

externalData = externalData || [];
Expand All @@ -43,7 +43,13 @@ define( [ 'xpath', 'jquery', 'enketo-js/plugins', 'enketo-js/extend', 'jquery.xp
// add external data to model
externalData.forEach( function( instance ) {
id = 'instance "' + instance.id + '"' || 'instance unknown';
that.xml.getElementById( instance.id ).appendChild( $.parseXML( instance.xmlStr ).firstChild );
instanceDoc = that.xml.getElementById( instance.id );
// remove any existing content that is just an XLSForm hack to pass ODK Validate
instanceRoot = instanceDoc.querySelector( 'root' );
if ( instanceRoot ) {
instanceDoc.removeChild( instanceRoot );
}
instanceDoc.appendChild( $.parseXML( instance.xmlStr ).firstChild );
} );
} catch ( e ) {
console.error( e );
Expand Down

0 comments on commit db1fd1d

Please sign in to comment.