Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3812: Only preload selected options for API-based select #3813

Merged
merged 2 commits into from
Jan 2, 2020
Merged

Fixes #3812: Only preload selected options for API-based select #3813

merged 2 commits into from
Jan 2, 2020

Conversation

hSaria
Copy link
Contributor

@hSaria hSaria commented Jan 1, 2020

Fixes: #3812

For API-based select fields, only preload the selected options. Other options are dynamically displayed and added via the API when selected.

Example for APISelect

No selection:

<select name="device_role" class="netbox-select2-api form-control select2-hidden-accessible" data-url="/api/dcim/device-roles/" required="" placeholder="Device role" id="id_device_role" tabindex="-1" aria-hidden="true">
  <option value="" selected="">---------</option>
</select>

After selection:

<select name="device_role" class="netbox-select2-api form-control select2-hidden-accessible" data-url="/api/dcim/device-roles/" required="" placeholder="Device role" id="id_device_role" tabindex="-1" aria-hidden="true">
  <option value="" selected="">---------</option>
  <option value="1">Access</option>
</select>

Existing selection:

<select name="device_role" class="netbox-select2-api form-control select2-hidden-accessible" data-url="/api/dcim/device-roles/" required="" placeholder="Device role" id="id_device_role" tabindex="-1" aria-hidden="true">
  <option value="1" selected="">Access</option>
</select>

Example for APISelectMultiple

This is output is from tagged VLANs which may change because of #3589. The list of choices is being manually overridden so that's why they're being created. In reality, the list isn't being used because the API select is dynamically fetching the options and their groups.

No selection:

<select name="tagged_vlans" class="netbox-select2-api form-control select2-hidden-accessible" data-url="/api/ipam/vlans/" data-full="" display-field="display_name" data-multiple="1" placeholder="None" id="id_tagged_vlans" multiple="" tabindex="-1" aria-hidden="true">
  <optgroup label="Global">
  </optgroup>
  <optgroup label="global-group-1">
  </optgroup>
  <optgroup label="London">
  </optgroup>
</select>

Groups are still created if present.

After selection (multiple):

<select name="tagged_vlans" class="netbox-select2-api form-control select2-hidden-accessible" data-url="/api/ipam/vlans/" data-full="" display-field="display_name" data-multiple="1" placeholder="None" id="id_tagged_vlans" multiple="" tabindex="-1" aria-hidden="true">
  <optgroup label="Global">
  </optgroup>
  <optgroup label="global-group-1">
  </optgroup>
  <optgroup label="London">
  </optgroup>
  <option value="1">1 (vlan1)</option>
  <option value="2">2 (vlan2)</option>
</select>

Existing selection (multiple):

<select name="tagged_vlans" class="netbox-select2-api form-control select2-hidden-accessible" data-url="/api/ipam/vlans/" data-full="" display-field="display_name" data-multiple="1" placeholder="None" id="id_tagged_vlans" multiple="" tabindex="-1" aria-hidden="true">
  <optgroup label="Global">
    <option value="2" selected="">2 (vlan2)</option>
  </optgroup>
  <optgroup label="global-group-1">
  </optgroup>
  <optgroup label="London">
    <option value="1" selected="">1 (vlan1)</option>
  </optgroup>
</select>

@jeremystretch jeremystretch merged commit fc5d07b into netbox-community:develop Jan 2, 2020
@hSaria hSaria deleted the 3812-optimize-select-api branch January 2, 2020 20:23
@lock lock bot locked as resolved and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only preload selected options for APISelect widgets
2 participants