Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.append() or .partial doesn't work with inputs #101

Open
shadowofsoul opened this issue Mar 12, 2013 · 1 comment
Open

.append() or .partial doesn't work with inputs #101

shadowofsoul opened this issue Mar 12, 2013 · 1 comment

Comments

@shadowofsoul
Copy link

I don't know if i'm doing it wrong or is a bug, but when i try to append a simple :

  map.class('formPayment').partial('<input type="hidden" name="token" value="EC-5EK42155LE6337258" />');
  map.class('formPayment').append('<input type="hidden" name="token" value="EC-5EK42155LE6337258" />');

i get:

  Error: Conflicting mappings for attribute class and value formPayment
  at closeTag (/node_modules/plates/lib/plates.js:85:15)
  at Array.sort (native)
  at compileMappings (/node_modules/plates/lib/plates.js:74:14)
  at Object.bind (/node_modules/plates/lib/plates.js:232:29)
  at Object.bind (/node_modules/plates/lib/plates.js:659:18)
  at Object.processHTML (/ut.js:21:22)
  at /main.js:531:28
  at fs.readFile (fs.js:176:14)
  at Object.oncomplete (fs.js:297:15)

there is any way i can fix this? also, there is a way to use an id and not a class to refer the object where the html should be added?

Regards

@davidamitchell
Copy link

append() and partial() are the same methods. partial() is just an alias to append(), you should only need to use one or the other not both.

try:

var Plates = require('plates');
var map = Plates.Map();

var html = '<div class="formPayment"></div>';
map.class('formPayment').partial('<input type="hidden" name="token" value="EC-5EK42155LE6337258" />');
//map.class('formPayment').append('<input type="hidden" name="token" value="EC-5EK42155LE6337258" />');

var output = Plates.bind(html, {}, map);
console.log(output);

outputs:

<div class="formPayment"><input type="hidden" name="token" value="EC-5EK42155LE6337258" /></div>

If you just want to use the id to bind you can rely on the implicit mapping see:

var Plates = require('plates');

var html = '<div id="test">Old Value</div>';
var data = { "test": "New Value" };

var output = Plates.bind(html, data); 

from the readme file. Or if you require an explicit mapping try:

var Plates = require('plates');
var map = Plates.Map();

var html = '<div id="test">Old Value</div>';
var data = { "foo": "New Value" };
map.where('id').is('test').use('foo');


var output = Plates.bind(html, data, map);
console.log(output); 

hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants