I have table in my twig template generated dynamically:
{% for a in abc %}
<tr>
<td>
{{ a.key }}
</td>
<td>
{{ a.value }}
</td>
<td class="td-actions">
<button id='EditSave' data-text="Save" data-id="{{ a.id }}">Edit</button>
<button id='Cancel' data-text="Cancel" style="display:none;">Cancel</button>
</td>
</tr>
{% endfor %}
I made my js function that will change attribute on click.
I am new in js and what I want to accomplish further is that on specific row 'Edit' click these two field become editable.
I know how to implement ajax but don't know how to access is with twig and jquery.
My func:
$(document).ready(function(){
//getting id of specific column
var id = $(this).data('id');
$("#EditSave").click(function(){
var btnText = $(this).text();
if(btnText === 'Edit')
{
$(this).text('Save');
$('#Cancel').show();
}
else
{
$(this).text('Edit');
$('#Cancel').hide();
}
});
$('#Cancel').click(function(){
$(this).hide();
$('#EditSave').text('Edit');
});
});
My Answer:
Rate this post
4 of 5 based on 4155 votesComments