Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can implement this in a way similar to this:</p> <h2>Your view:</h2> <pre><code>&lt;div data-shipment-mode="A" style="display:none;"&gt; fields that should only be shown for shipment mode A &lt;/div&gt; &lt;div data-shipment-mode="B" style="display:none;"&gt; fields that should only be shown for shipment mode B &lt;/div&gt; </code></pre> <h2>Your JavaScript:</h2> <pre><code>$(document).ready(function() { $('id-of-shipment-select-menu').change(function() { var successHandler = function(data) { var mode = data.mode; $("div[data-shipment-mode!=" + mode + "]").hide(); $("div[data-shipment-mode=" + mode + "]").show(); }; var shipmentId = $(this).val(); /* replace service_url with the appropriate controller/action */ $.getJSON("/service_url/" + shipmentId, successHandler); }); }); </code></pre> <p>Initially all mode-dependent fields are hidden. Then when you select a shipment, the <code>change</code> callback will be invoked. It sends a request to a service (controller action) that returns the mode for the given shipment. And you use this mode and only show those divs that their <code>data-shipment-mode</code> has the same value.</p> <p>You can even expand this, and when you hide a div, you can clear the values of all the inputs (and selects, etc.) within it as well as disabling them.</p> <p>You can avoid sending the request to the server, if you embed the mode for each shipment in its option tag:</p> <h2>View:</h2> <pre><code>&lt;option id="A_SHIPMENT_ID" data-shipment-mode="SHIPMENT_MODE_FOR_THIS_SHIPMENT"&gt; Shipment A &lt;/option&gt; </code></pre> <h2>JavaScript:</h2> <pre><code>$(document).ready(function() { $('id-of-shipment-select-menu').change(function(e) { var mode = $(e.target).data("shipment-mode"); $("div[data-shipment-mode!=" + mode + "]").hide(); $("div[data-shipment-mode=" + mode + "]").show(); }); }); </code></pre>
 

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