Note that there are some explanatory texts on larger screens.

plurals
  1. POIn ATK4, how to reload the page with value chosen in a select box
    primarykey
    data
    text
    <p>I have a page with a dropdown list defined as follows</p> <pre><code>$memb=$this-&gt;api-&gt;db-&gt;dsql()-&gt;table('vscrum_member m') -&gt;field('m.id') -&gt;field('m.name') -&gt;where('m.team_id',$p-&gt;api-&gt;auth-&gt;get('team_id')) -&gt;order('m.xlastname, m.xfirstname') -&gt;do_getAssoc(); $f=$p-&gt;add('Form'); $l1=$f-&gt;addField('dropdown','member')-&gt;setValueList($memb); </code></pre> <p>I need the page to be reloaded passing the current value of the dropdown when it is changed by the user (either GET or POST is fine).</p> <p>In ATK4, i can cause a redirect of the page with this </p> <pre><code>$l1-&gt;js('change')-&gt;univ()-&gt;redirect($this-&gt;api-&gt;getDestinationURL(null)); </code></pre> <p>and in theory, you can add an array of values as the second parameter which become GET variables </p> <pre><code>$l1-&gt;js('change')-&gt;univ() -&gt;redirect($this-&gt;api-&gt;getDestinationURL(null, array('member'=&gt;123); </code></pre> <p>but as i dont know the value chosen on the client side, this doesnt help. In javascript, you can select the current value of a select box by using </p> <pre><code> this.options[this.selectedIndex].value </code></pre> <p>and in jquery you can use </p> <pre><code> $('#name').val(); </code></pre> <p>but so far, the closest i've got is using </p> <pre><code>$l1-&gt;js('change')-&gt;univ()-&gt;redirect($this-&gt;api-&gt;getDestinationURL(null, array('member'=&gt;$l1-&gt;js(true)-&gt;val()))); </code></pre> <p>This does the redirect to </p> <pre><code>http://localhost/test1/scrumwall? member=%24%28%27%23test1_scrumwall_form_member%27%29.val%28%29 </code></pre> <p>So any ideas what the correct syntax would be so that it evaluates the id of the option chosen, rather than putting the name of the dropdown list as the parameter value ?</p> <p>The $l1->js('change') bit adds an onchange="" to the dropdown list - maybe there is some way to insert javascript directly between the quotes but couldnt see any examples. </p> <p>I tried it this way </p> <pre><code> $l1-&gt;js('change')-&gt;univ()-&gt;js(null, "window.location='http://localhost/test1/scrumwall?member='+this.options[this.selectedIndex].value"); </code></pre> <p>but it doesnt put this between the quotes on the onchange, instead it adds it as a jquery function (see result in browser view source below) bound to the dropdown but this also doesnt work. </p> <pre><code>$('#test1_scrumwall_form_member').bind('change',function(ev){ ev.preventDefault();ev.stopPropagation(); $('#test1_scrumwall_form_member').univ().js(null,'window.location=\x27 http://localhost/test1/scrumwall?member=\x27+this.options[this.selectedIndex].value') }); </code></pre> <p>so i cant figure out how to do this with ATK4. Any assistance appreciated.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload