flatiron / plates

Light-weight, logic-less, DSL-free, templates for all javascript environments!
MIT License
831 stars 69 forks source link

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

Open shadowofsoul opened 11 years ago

shadowofsoul commented 11 years ago

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 commented 11 years ago

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