-1

i rephrase.

This is the view:

def v_tools(request, snCI=0):
    logger.info(f"snCI={snCI}")

From the template:

<button id="submit-button" type="button" title="tools" hx-get="{% url 'tools-baseline' snCI='placeholder' %}" hx-target="#dialog_tools" class="btn-special">Tool</button>

the js script:

$(".checkboxAll").on("change", function() {
        build_hx_get();
    });
    
    function build_hx_get() {

        var checkboxes = $('input[name=selectedcis]:checked');
        var values = checkboxes.map(function() {
            return $(this).val();
        }).get();
        selectedValuesString = values.join(',');
        console.log(selectedValuesString);      

        var url = "/base/tools/?snCI=" + selectedValuesString;
        
        var timestamp = new Date().getTime();
        url += "&timestamp=" + timestamp;

        $('#submit-button').attr('hx-get', url);
    };

i the debugger i see this:

<button id="submit-button" type="button" title="tools" hx-get="/base/tools/?snCI=servername1,servername2&timestamp=1685540724092" hx-target="#dialog_tools" class="btn-special">Tool</button>

but the output from the logger says:

snCI=placeholder
user625079
  • 125
  • 1
  • 13
  • Django template tags `{%%}` are evaluated on the server, but HX is running in the browser…!? See [What is the difference between client-side and server-side programming?](https://stackoverflow.com/q/13840429/476) for the same thing with different languages. – deceze May 31 '23 at 12:27
  • i get that, but as i change it to rendered state, then it is still executing the old hx-get – user625079 May 31 '23 at 13:00
  • It's unclear what you're changing where and what result you expect. If you change some `{% ... %}` string client-side, Django is not going to re-evaluate that tag and give you a different URL. If you try to interpolate `selectedValuesString` into the template on the server: if `selectedValuesString` is a Javascript value, it won't exist on the server. – deceze May 31 '23 at 13:24
  • i rephrase the question with some details – user625079 May 31 '23 at 13:50

1 Answers1

0

was solved by using htmx in jquery and make the script activated by button click.

$('#submit-tool').click(function () {
    var checkboxes = $('input[name=selectedcis]:checked');
    var values = checkboxes.map(function() {
        return $(this).val();
    }).get();
    selectedValuesString = values.join(',');
    var url = "/base/tools/"+encodeURIComponent(selectedValuesString);
    htmx.ajax('GET', url, {target:'#dialog_tools'})        

});
user625079
  • 125
  • 1
  • 13