| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Transform auto-generated CollectionType of Symfony into given HTML template
Just download and import the js file into your project, and don't forget to import the jQuery library.
$builder
->add('firstField', TextType::class, array(
'attr' => array(
'data-name' => 'first'//---give this attribute any name you want
)
))
->add('secondField', TextType::class, array(
'attr' => array(
'data-name' => 'second'
)
))
->add('thirdField', TextType::class, array(
'attr' => array(
'data-name' => 'third'
)
))
;function myTemplate() {
return `<div>
<table>
<tr>
<td>First field:</td><td>#first#</td>
<tr>
<tr>
<td>Second field:</td><td>#second#</td>
<tr>
<tr>
<td>Third field:</td><td>#third#</td>
<tr>
</table>
</div><hr>`;
}// declare a counter variabel
// in case of update you can counter the dom children ex: var _counter = $('#collection-div').children().length;
var _counter = 0;
$('#btnAdd').on('click', function (){
// you just need to pass the dom that contains the data-prototype attribute along with your template function
var temp = SFCollectionAnalyzer.buildTemplate($('#collection-div'), myTemplate());
var block = temp.replace(/__name__/g, _counter);//--temp is still using "__name__" so you just need to replace it with the counter
$('#div-where-to-insert-collection').append(block);
_counter++;
});| Back | FazBrowse Home | New Git URL |