symfony twig dynamic from action path

652 views Asked by At

I have a form, I want to change its path of action using js variable.

This is current working code:

if ($('#totalRecordsOfQuery').val() < 100) {
    $('#postbackform').attr('action', "{{ path('_getAllRecordsStudentsProgress') }}");
    $('#postbackform').submit();
    $('#postbackform').attr('action', "{{ path('xyz) }}");
}

I want something like:

var allRecordsActions = "_getAllRecordsStudentsProgress";
if ($('#totalRecordsOfQuery').val() < 100) {
    $('#postbackform').attr('action', "{{ path(allRecordsActions) }}");
    $('#postbackform').submit();
    $('#postbackform').attr('action', "{{ path('xyz') }}");
}  

With this code, I'm getting an error:

Variable "allRecordsActions" does not exist.

1

There are 1 answers

2
Zeljka On
var allRecordsActions = "_getAllRecordsStudentsProgress";
var concatenation= '{{ path("'+ allRecordsActions +'") }}';
        if($('#totalRecordsOfQuery').val()<100){
            $('#postbackform').attr('action', concatenation);
            $('#postbackform').submit();
            $('#postbackform').attr('action', "{{ path('xyz') }}");
        } 

or

var allRecordsActions = "_getAllRecordsStudentsProgress";
if($('#totalRecordsOfQuery').val()<100){
    $('#postbackform').attr('action', '{{ path("'+ allRecordsActions +'") }}');
    $('#postbackform').submit();
    $('#postbackform').attr('action', "{{ path('xyz') }}");
}