Note that there are some explanatory texts on larger screens.

plurals
  1. POStore & retrieve the identifiers of a multipliable widget's instances
    primarykey
    data
    text
    <p>The aim is to remove only the last row at any time and only by the last remove button.</p> <p>There is a user interface which building up as a multiplication of the same row. The number of rows are controlled by 'Add' &amp; 'Remove' buttons which are also elements of the row. The problem is that the hidden widgets - that are applied for each row to distinguish the instances by storing their row numbers - are storing the very same number which is the last one. Except the first (0) hidden widget which stores the proper number (0). Where am I missing the point? How should this be resolved?</p> <p>As per the remove buttons have two different purposes (not detailed here), we use a cacheService to distinguish the last row from all the others. Only the last row should be removed at any time.</p> <pre><code> var cache = CacheService.getPrivateCache(); </code></pre> <p>we clear the cache and create the first instance</p> <pre><code>function doGet() { var app = UiApp.createApplication(); app.add(app.createVerticalPanel().setId('mainContainer')); cache.removeAll([]); ui(0); cache.put('numberOfInstances',0); return app; } </code></pre> <p>each instance is held by a horizontal panel which contains the mentioned hidden widget, a label which informs about the instance number, and the Add &amp; Remove buttons.</p> <pre><code>function ui(instance) { var app = UiApp.getActiveApplication(); var eventContainer = app.createHorizontalPanel() .setId('eventContainer' + instance); var instanceContainer = app.createHidden('instanceContainer',instance); var showInstance = app.createLabel(instance) .setId('showInstance' + instance); var addButton = app.createButton('Add') .setId('add' + instance) .addClickHandler(app.createClientHandler() .forEventSource().setEnabled(false)) //avoiding multiple click during server response .addClickHandler(app.createServerHandler('add') .addCallbackElement(instanceContainer)); var removeButton = app.createButton('X') .addClickHandler(app.createServerHandler('remove') .addCallbackElement(instanceContainer)); app.getElementById('mainContainer') .add(eventContainer .add(instanceContainer) .add(showInstance) .add(addButton) .add(removeButton)); return app; } </code></pre> <p>and the event handling...</p> <pre><code>function add(inst) { var app = UiApp.getActiveApplication(); var instance = Number(inst.parameter.instanceContainer); ui(instance+1); cache.put('numberOfInstances',instance+1); return app; } function remove(inst) { var app = UiApp.getActiveApplication(); var instance = Number(inst.parameter.instanceContainer); var numberOfInstances = cache.get('numberOfInstances') if( (instance != 0) &amp;&amp; (instance = numberOfInstances) ) { app.getElementById('mainContainer').remove(app.getElementById('eventContainer' + instance)); cache.put('numberOfInstances',instance-1); app.getElementById('add' + (instance-1)).setEnabled(true); } //avoiding multiple click during server response return app; } </code></pre> <p>The aim is to remove only the last row at any time and only by the last remove button.</p> <p>Many Thanks.</p>
    singulars
    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.
    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