Invalidate snippet when form value changes

Notice: This thread is very old.
izytech_thomas
Member | 11
+
0
-

I'm trying to achive an update of an snippet when the user changes a value in a form. Is there any working examples of this?

Vojtěch Dobeš
Gold Partner | 1316
+
0
-

Well, you just to need to make ajax request hooked in change event of some form element, and process the response, right? If you use nette.ajax.js you get processing of response baked in.

izytech_thomas
Member | 11
+
0
-

I tried this but I'm clearly missing something. how do I get it to update

<ul n:snippet=“itemsContainer”>

<script>
    jQuery(window).ready(function() {
      $('#frm-formOrderProduct').on('change input', function () {
        var productsFrmChanged = false;
        var pars;
        var frmProductValues = document.getElementById("frm-formOrderProduct");

        for (var i=0;i<frmProductValues.length;i++){
            if (frmProductValues.elements[i].value !== 'undefined')
            {
                productsFrmChanged = true;
                pars += ('&'+(frmProductValues.elements[i].id) + '=' + (frmProductValues.elements[i].value));

            }
        }



        if (productsFrmChanged===true) {
            $.nette.ajax({
                'url': '?do=update',
                'data': pars
            });
        }
      });
    });
</script>

I see the get request on server side so it does a request when anything changes in the #frm-formOrderProduct but how do I get it to update the itemsCointainer snippet?

Last edited by izytech_thomas (2014-05-15 12:49)

izytech_thomas
Member | 11
+
0
-

Well, you just to need to make ajax request hooked in change event of some form element, and process the response, right? If you use nette.ajax.js you get processing of response baked in.

How do I do this? Is there any examples with nette from and ajaxhook?

Vojtěch Dobeš
Gold Partner | 1316
+
0
-

Do you invalidate any snippet serverside?

izytech_thomas
Member | 11
+
0
-

I do a redraw, since invalidate i deprecated, or should I use invalidate even if it seems deprecated?

public function handleUpdate($id)
{
    if ($this->isAjax()){
        $this->template->list = array('item1'.rand(1,1000),'item2'.rand(1000,2000),'item3'.rand(4,5000));
    }
    $this->redrawControl('itemsContainer');
}

random values is only for testing…